#14193 Guard additional null sub-accessor derefs in pick handling

findCellAndGridIndex and ijkFromCellIndex shared the same latent
null-pointer pattern as the context menu crash: the outer case/view was
null-checked, but a sub-accessor that can also return nullptr was
dereferenced without a guard. These are reachable from the same pick and
context-menu flow when a case is still loading, in a comparison view, or
being torn down.

- findCellAndGridIndex: guard mainGrid() and geoMechData()
- ijkFromCellIndex: guard eclipseCaseData() (matching isRadialGrid) and
  femParts()
This commit is contained in:
Magne Sjaastad authored and Kristian Bendiksen committed 2026-06-10 08:46:39 +02:00
1 parent 50c9d3f446
commit 22f9053401
1 file changed
+4 -4
@@ -1118,13 +1118,13 @@ void RiuViewerCommands::findCellAndGridIndex( Rim3dView* m
eclipseCase = dynamic_cast<RimEclipseCase*>( mainOrComparisonView->ownerCase() );
}
if ( eclipseCase )
if ( eclipseCase && eclipseCase->mainGrid() )
{
const RigCell& cell = eclipseCase->mainGrid()->cell( globalCellIndex );
*cellIndex = cell.gridLocalCellIndex();
*gridIndex = cell.hostGrid()->gridIndex();
}
else if ( geomechCase )
else if ( geomechCase && geomechCase->geoMechData() )
{
RigFemPartCollection* parts = geomechCase->geoMechData()->femParts();
auto [partId, elementIdx] = parts->partIdAndElementIndex( globalCellIndex );
@@ -1223,12 +1223,12 @@ void RiuViewerCommands::ijkFromCellIndex( Rim3dView* mainOrComparisonView, size_
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>( mainOrComparisonView );
RimGeoMechView* geomView = dynamic_cast<RimGeoMechView*>( mainOrComparisonView );
if ( eclipseView && eclipseView->eclipseCase() )
if ( eclipseView && eclipseView->eclipseCase() && eclipseView->eclipseCase()->eclipseCaseData() )
{
eclipseView->eclipseCase()->eclipseCaseData()->grid( gridIdx )->ijkFromCellIndex( cellIndex, i, j, k );
}
if ( geomView && geomView->geoMechCase() )
if ( geomView && geomView->geoMechCase() && geomView->femParts() )
{
geomView->femParts()->part( gridIdx )->getOrCreateStructGrid()->ijkFromCellIndex( cellIndex, i, j, k );
}