Fix crash on project reset when accessing null project during teardown

RimProject::current() can return null while the project is being torn down. Guard the project access in the view-window lookups and valid-comparison-views query with an if-init statement so they return empty instead of dereferencing null.
This commit is contained in:
Magne Sjaastad committed 2026-06-19 16:38:41 +02:00
1 parent 3ae102ba6c
commit 8369fad029
3 files changed
+24 -11

No files matched your search

@@ -604,15 +604,20 @@ std::vector<Rim3dView*> Rim3dView::validComparisonViews() const
auto isIntersectionView = []( const Rim3dView* view ) { return dynamic_cast<const Rim2dIntersectionView*>( view ) != nullptr; };
std::vector<Rim3dView*> validComparisonViews;
for ( auto view : RimProject::current()->allViews() )
// Project can be null while it is being torn down.
if ( auto project = RimProject::current() )
{
if ( dynamic_cast<RimSeismicView*>( view ) ) continue;
bool isSameViewType = isIntersectionView( this ) == isIntersectionView( view );
if ( view != this && isSameViewType )
for ( auto view : project->allViews() )
{
validComparisonViews.push_back( view );
if ( dynamic_cast<RimSeismicView*>( view ) ) continue;
bool isSameViewType = isIntersectionView( this ) == isIntersectionView( view );
if ( view != this && isSameViewType )
{
validComparisonViews.push_back( view );
}
}
}
@@ -1208,9 +1208,13 @@ std::vector<RimViewWindow*> RiuMainWindow::viewWindows()
{
std::vector<RimViewWindow*> views;
for ( auto v : RimProject::current()->descendantsOfType<Rim3dView>() )
// Project can be null while it is being torn down.
if ( auto project = RimProject::current() )
{
if ( v->dockWidget() ) views.push_back( v );
for ( auto v : project->descendantsOfType<Rim3dView>() )
{
if ( v->dockWidget() ) views.push_back( v );
}
}
return views;
@@ -797,9 +797,13 @@ std::vector<RimViewWindow*> RiuPlotMainWindow::viewWindows()
{
std::vector<RimViewWindow*> views;
for ( auto v : RimProject::current()->descendantsOfType<RimPlotWindow>() )
// Project can be null while it is being torn down.
if ( auto project = RimProject::current() )
{
if ( v->dockWidget() ) views.push_back( v );
for ( auto v : project->descendantsOfType<RimPlotWindow>() )
{
if ( v->dockWidget() ) views.push_back( v );
}
}
return views;