#12558 Summary Plot: Fix crash when deleting sub plots.

The std::unique_ptr<RiuPlotWidget> would delete the widget when
RimSummaryPlot object was recreated. This would lead to a
double-delete since the RiuPlotWidget was already deleted by Qt
through the parent-child relationship.

Fixed by using QPointer, and leaving the cleanup to Qt.

Fixes #12558.
This commit is contained in:
Kristian Bendiksen committed 2025-08-11 15:04:24 +02:00
1 parent c47d7b13fd
commit f793abe46d
2 files changed
+5 -11

No files matched your search

@@ -1898,17 +1898,12 @@ void RimSummaryPlot::deletePlotCurvesAndPlotWidget()
if ( isDeletable() )
{
detachAllPlotItems();
if ( plotWidget() )
{
plotWidget()->setParent( nullptr );
}
deleteAllPlotCurves();
if ( m_summaryPlot )
{
m_summaryPlot.reset();
// The RiuPlotWidget is owned by Qt, and will be deleted when its parent is destructed.
m_summaryPlot.clear();
}
}
}
@@ -2604,9 +2599,10 @@ void RimSummaryPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering&
//--------------------------------------------------------------------------------------------------
RiuPlotWidget* RimSummaryPlot::doCreatePlotViewWidget( QWidget* mainWindowParent )
{
CAF_ASSERT( mainWindowParent );
if ( !plotWidget() )
{
m_summaryPlot = std::make_unique<RiuSummaryQwtPlot>( this, mainWindowParent );
m_summaryPlot = new RiuSummaryQwtPlot( this, mainWindowParent );
QObject::connect( plotWidget(), SIGNAL( curveOrderNeedsUpdate() ), this, SLOT( onUpdateCurveOrder() ) );
@@ -2640,8 +2636,6 @@ RiuPlotWidget* RimSummaryPlot::doCreatePlotViewWidget( QWidget* mainWindowParent
updatePlotTitle();
}
plotWidget()->setParent( mainWindowParent );
return plotWidget();
}
@@ -338,7 +338,7 @@ private:
caf::PdmChildArrayField<RimPlotAxisPropertiesInterface*> m_axisPropertiesArray;
std::unique_ptr<RiuSummaryPlot> m_summaryPlot;
QPointer<RiuSummaryPlot> m_summaryPlot;
std::unique_ptr<QwtPlotTextLabel> m_plotInfoLabel;
std::unique_ptr<RimSummaryPlotNameHelper> m_nameHelperAllCurves;