Janitor: Guard null pointer access

This commit is contained in:
Magne Sjaastad 2021-12-29 09:31:51 +01:00
parent bca2fadc28
commit 9023b01cfa

View File

@ -318,22 +318,26 @@ void RiuMainWindowBase::removeViewerFromMdiArea( QMdiArea* mdiArea, QWidget* vie
{ {
bool wasMaximized = viewer && viewer->isMaximized(); bool wasMaximized = viewer && viewer->isMaximized();
QMdiSubWindow* subWindowBeingClosed = findMdiSubWindow( viewer ); bool removedSubWindowWasActive = false;
bool removedSubWindowWasActive = false;
if ( subWindowBeingClosed->isActiveWindow() )
{
// If we are removing the active window, we will need a new active window
// Start by making the window inactive so Qt doesn't pick the active window itself
mdiArea->setActiveSubWindow( nullptr );
removedSubWindowWasActive = true;
}
mdiArea->removeSubWindow( subWindowBeingClosed );
// These two lines had to be introduced after themes was used QMdiSubWindow* subWindowBeingClosed = findMdiSubWindow( viewer );
// Probably related to polish/unpolish of widgets in an MDI setting if ( subWindowBeingClosed )
// https://github.com/OPM/ResInsight/issues/6676 {
subWindowBeingClosed->hide(); if ( subWindowBeingClosed->isActiveWindow() )
subWindowBeingClosed->deleteLater(); {
// If we are removing the active window, we will need a new active window
// Start by making the window inactive so Qt doesn't pick the active window itself
mdiArea->setActiveSubWindow( nullptr );
removedSubWindowWasActive = true;
}
mdiArea->removeSubWindow( subWindowBeingClosed );
// These two lines had to be introduced after themes was used
// Probably related to polish/unpolish of widgets in an MDI setting
// https://github.com/OPM/ResInsight/issues/6676
subWindowBeingClosed->hide();
subWindowBeingClosed->deleteLater();
}
QList<QMdiSubWindow*> subWindowList = mdiArea->subWindowList( QMdiArea::ActivationHistoryOrder ); QList<QMdiSubWindow*> subWindowList = mdiArea->subWindowList( QMdiArea::ActivationHistoryOrder );
if ( !subWindowList.empty() ) if ( !subWindowList.empty() )