From 73d598ee7e4177352c97a86c5fc2b061437f5d27 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 25 Apr 2022 15:34:04 +0200 Subject: [PATCH] Fix crash during delete of multiplot --- ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp | 11 +++++++++++ ApplicationLibCode/ProjectDataModel/RimMultiPlot.h | 4 ++++ ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp | 2 ++ ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp | 3 +++ 4 files changed, 20 insertions(+) diff --git a/ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp b/ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp index 121e1d804a..7912416814 100644 --- a/ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimMultiPlot.cpp @@ -45,6 +45,7 @@ CAF_PDM_SOURCE_INIT( RimMultiPlot, "MultiPlot" ); /// //-------------------------------------------------------------------------------------------------- RimMultiPlot::RimMultiPlot() + : m_isValid( true ) { CAF_PDM_InitObject( "Multi Plot", ":/MultiPlot16x16.png" ); @@ -84,6 +85,8 @@ RimMultiPlot::RimMultiPlot() //-------------------------------------------------------------------------------------------------- RimMultiPlot::~RimMultiPlot() { + m_isValid = false; + removeMdiWindowFromMdiArea(); m_plots.deleteAllChildObjects(); @@ -897,3 +900,11 @@ std::vector RimMultiPlot::fieldsToShowInToolbar() { return { &m_pagePreviewMode, &m_columnCount, &m_rowsPerPage }; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimMultiPlot::isValid() const +{ + return m_isValid; +} diff --git a/ApplicationLibCode/ProjectDataModel/RimMultiPlot.h b/ApplicationLibCode/ProjectDataModel/RimMultiPlot.h index a0af751746..93218b3d41 100644 --- a/ApplicationLibCode/ProjectDataModel/RimMultiPlot.h +++ b/ApplicationLibCode/ProjectDataModel/RimMultiPlot.h @@ -107,6 +107,8 @@ public: virtual std::vector fieldsToShowInToolbar(); + bool isValid() const; + protected: QImage snapshotWindowContent() override; @@ -169,4 +171,6 @@ protected: private: caf::PdmChildArrayField m_plots; + + bool m_isValid; }; diff --git a/ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp b/ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp index 056a38a33d..320ae84e3b 100644 --- a/ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp +++ b/ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp @@ -492,6 +492,8 @@ bool RiuMultiPlotBook::showYAxis( int row, int column ) const //-------------------------------------------------------------------------------------------------- void RiuMultiPlotBook::performUpdate( bool regeneratePages ) { + if ( !m_plotDefinition || !m_plotDefinition->isValid() ) return; + applyLook(); if ( regeneratePages || m_pages.size() == 0 ) { diff --git a/ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp b/ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp index ca6c3d8e61..3ba10d26a9 100644 --- a/ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp +++ b/ApplicationLibCode/UserInterface/RiuMultiPlotPage.cpp @@ -563,6 +563,9 @@ bool RiuMultiPlotPage::showYAxis( int row, int column ) const //-------------------------------------------------------------------------------------------------- void RiuMultiPlotPage::performUpdate( RiaDefines::MultiPlotPageUpdateType whatToUpdate ) { + auto multiPlot = dynamic_cast( m_plotDefinition.p() ); + if ( !multiPlot || !multiPlot->isValid() ) return; + if ( whatToUpdate == RiaDefines::MultiPlotPageUpdateType::ALL ) { applyLook();