Bug 164166 - Duplicate Sheet with histogram chart crashes
Summary: Duplicate Sheet with histogram chart crashes
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Chart (show other bugs)
Version:
(earliest affected)
25.2.0.0 alpha0+
Hardware: All All
: medium normal
Assignee: Devansh Varshney
URL:
Whiteboard:
Keywords: implementationError
Depends on:
Blocks: Histogram-Chart
  Show dependency treegraph
 
Reported: 2024-12-04 16:47 UTC by Regina Henschel
Modified: 2025-03-17 21:36 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Data for quickly creating a Histogram chart (13.58 KB, application/vnd.oasis.opendocument.spreadsheet)
2024-12-04 16:47 UTC, Regina Henschel
Details
Backtrace (9.64 KB, text/x-log)
2024-12-04 18:05 UTC, Rafael Lima
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Regina Henschel 2024-12-04 16:47:17 UTC
Created attachment 197937 [details]
Data for quickly creating a Histogram chart

Open attached document.
Select the data.
Insert Histogram chart with default values.
Duplicate the sheet.
=> Crash

Tested in Version: 25.2.0.0.alpha1+ (X86_64) / LibreOffice Community
Build ID: 44ccd392be12dad23e216fb3eb2c2e5b275eee75
CPU threads: 32; OS: Windows 11 X86_64 (10.0 build 26100); UI render: Skia/Raster; VCL: win
Locale: de-DE (de_DE); UI: en-US
Calc: threaded
Comment 1 Rafael Lima 2024-12-04 18:05:02 UTC
Created attachment 197939 [details]
Backtrace

I can confirm this crash in

Version: 25.2.0.0.alpha1+ (X86_64) / LibreOffice Community
Build ID: 383e3aef8438141bfc953f0cca094f6d3d7ed007
CPU threads: 12; OS: Linux 6.11; UI render: default; VCL: kf6 (cairo+wayland)
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: CL threaded

I have added a backtrace of the crash.
Comment 2 m_a_riosv 2024-12-04 20:13:21 UTC
Maybe a dup of https://bugs.documentfoundation.org/show_bug.cgi?id=162147
Comment 3 Marina Latini (SUSE) 2024-12-05 15:02:19 UTC
can't repro on: 
Version: 25.2.0.0.alpha1+ (X86_64) / LibreOffice Community
Build ID: ec4415d2a78b1c0fb5eab5baea88508d6b9db43b
CPU threads: 20; OS: Linux 5.14; UI render: default; VCL: kf5 (cairo+xcb)
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 4 Regina Henschel 2025-03-16 23:02:00 UTC
The crash happens in
https://opengrok.libreoffice.org/xref/core/chart2/source/tools/DataSourceHelper.cxx?r=d0fe2b9cf985bd77483a716c825734956f3dc828#285
uno::Reference< chart2::data::XLabeledDataSequence > xCategories( xDiagram->getCategories() );

The crash happens, because xDiagram is empty in the describes scenario having a histogram chart. It is not yet clear why xDiagram is empty.
Comment 5 Devansh Varshney 2025-03-17 21:26:01 UTC
HistogramChart class inherits from BarChart view which is responsible for rendering the histogram. However, when duplicating a sheet, the chart might not be fully initialized or reattached to the new sheet’s context?

I will look in this further, this is what I suspect, could be one of the possibility.
Comment 6 Devansh Varshney 2025-03-17 21:36:33 UTC
Right now I am in this file with debugger -

chart2/source/tools/AxisHelper.cxx#181

else if( xChartDoc.is() && xChartDoc->hasInternalDataProvider() && nDimensionIndex == 0 ) //maybe date axis
            {
                rtl::Reference< Diagram > xDiagram( xChartDoc->getFirstChartDiagram() );
                if( xDiagram->isSupportingDateAxis() )
                {
                    nNumberFormatKey = DiagramHelper::getDateNumberFormat( xChartDoc );
                }
                else
                {
                    rtl::Reference< DataSource > xSource = DataSourceHelper::getUsedData( *xChartDoc );
                    if( xSource.is() )
                    {
                        std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aXValues(
                            DataSeriesHelper::getAllDataSequencesByRole( xSource->getDataSequences(), u"values-x"_ustr ) );
                        if( aXValues.empty() )
                        {
                            uno::Reference< chart2::data::XLabeledDataSequence > xCategories( xDiagram->getCategories() );
                            if( xCategories.is() )
                            {
                                Reference< data::XDataSequence > xSeq( xCategories->getValues());
                                if( xSeq.is() )
                                {
                                    bool bHasValidDoubles = false;
                                    double fTest=0.0;
                                    Sequence< uno::Any > aCats( xSeq->getData() );
                                    sal_Int32 nCount = aCats.getLength();
                                    for( sal_Int32 i = 0; i < nCount; ++i )
                                    {
                                        if( (aCats[i]>>=fTest) && !std::isnan(fTest) )
                                        {
                                            bHasValidDoubles=true;
                                            break;
                                        }
                                    }
                                    if( bHasValidDoubles )
                                        nNumberFormatKey = DiagramHelper::getDateNumberFormat( xChartDoc );
                                }
                            }
                        }
                    }
                }
                bFormatSet = true;
            }