Avoid GUI cleanup on a main window being destroyed

This commit is contained in:
Magne Sjaastad
2026-08-24 09:10:22 +02:00
parent 7032832774
commit d53e5b48b3
4 changed files with 33 additions and 0 deletions
@@ -190,6 +190,8 @@ RiuMainWindow::RiuMainWindow()
//--------------------------------------------------------------------------------------------------
RiuMainWindow::~RiuMainWindow()
{
setBeingDestroyed();
setPdmRoot( nullptr );
if ( m_pdmUiPropertyView )
@@ -329,6 +331,10 @@ void RiuMainWindow::cleanupGuiCaseClose()
//--------------------------------------------------------------------------------------------------
void RiuMainWindow::cleanupGuiBeforeProjectClose()
{
// Closing the last window can trigger a project close while this window is being destroyed. Accessing the
// GUI of a window being destroyed is not safe.
if ( isBeingDestroyed() ) return;
for ( auto v : viewWindows() )
{
v->removeWindowFromDock();
@@ -73,6 +73,7 @@ RiuMainWindowBase::RiuMainWindowBase()
, m_blockSubWindowActivation( false )
, m_blockSubWindowProjectTreeSelection( false )
, m_hasBeenVisible( false )
, m_isBeingDestroyed( false )
, m_windowMenu( nullptr )
{
ads::CDockManager::setAutoHideConfigFlags( ads::CDockManager::DefaultAutoHideConfig );
@@ -795,6 +796,22 @@ void RiuMainWindowBase::addDefaultEntriesToWindowsMenu()
m_windowMenu->addAction( m_maximizeWindowsAction );
}
//--------------------------------------------------------------------------------------------------
/// Called when the destructor of a main window starts. Used to avoid operations on a window being destroyed.
//--------------------------------------------------------------------------------------------------
void RiuMainWindowBase::setBeingDestroyed()
{
m_isBeingDestroyed = true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuMainWindowBase::isBeingDestroyed() const
{
return m_isBeingDestroyed;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -92,6 +92,9 @@ public:
void setBlockViewSelectionOnSubWindowActivated( bool block );
bool isBlockingViewSelectionOnSubWindowActivated() const;
void setBeingDestroyed();
bool isBeingDestroyed() const;
ads::CDockManager* dockManager() const;
QString dockWidgetStateString() const;
@@ -167,6 +170,7 @@ private:
bool m_blockSubWindowActivation;
bool m_blockSubWindowProjectTreeSelection;
bool m_hasBeenVisible;
bool m_isBeingDestroyed;
ads::CDockManager* m_dockManager;
};
@@ -122,6 +122,8 @@ RiuPlotMainWindow::RiuPlotMainWindow()
//--------------------------------------------------------------------------------------------------
RiuPlotMainWindow::~RiuPlotMainWindow()
{
setBeingDestroyed();
m_summaryPlotManagerView->showProperties( nullptr );
setPdmRoot( nullptr );
}
@@ -225,6 +227,10 @@ void RiuPlotMainWindow::initializeGuiNewProjectLoaded()
//--------------------------------------------------------------------------------------------------
void RiuPlotMainWindow::cleanupGuiBeforeProjectClose()
{
// Closing the last window can trigger a project close while this window is being destroyed. Accessing the
// GUI of a window being destroyed is not safe.
if ( isBeingDestroyed() ) return;
for ( auto v : viewWindows() )
{
v->removeWindowFromDock();