Fix crash when selecting a cell in 2d intersection view by adding null pointer guards.

This commit is contained in:
jonjenssen authored and JJ committed 2026-01-06 19:21:36 +01:00
1 parent 51b1bbda6c
commit 1181799ec2
1 file changed
+29 -22
@@ -370,33 +370,40 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
// - If SHIFT is pressed, show mesh lines for the main grid cell
// - If SHIFT is not pressed, show mesh lines for the LGR cells
//
const bool isShiftPressed = ( keyboardModifiers & Qt::ShiftModifier ) != 0;
const bool isShiftPressed = ( keyboardModifiers & Qt::ShiftModifier ) != 0;
bool showLgrMeshLines = false;
bool showLgrMeshLines = false;
auto eclipseView = dynamic_cast<RimEclipseView*>( mainOrComparisonView );
auto mainGrid = eclipseView->eclipseCase()->eclipseCaseData()->mainGrid();
auto currentGrid = mainGrid->gridByIndex( gridIndex );
if ( mainGrid && !currentGrid->isMainGrid() )
if ( auto eclipseView = dynamic_cast<RimEclipseView*>( mainOrComparisonView ) )
{
bool selectMainGridCell = false;
if ( currentGrid->isRadial() )
if ( ( eclipseView->eclipseCase() != nullptr ) && ( eclipseView->eclipseCase()->eclipseCaseData() != nullptr ) )
{
selectMainGridCell = !isShiftPressed;
showLgrMeshLines = !isShiftPressed;
}
else
{
selectMainGridCell = isShiftPressed;
}
if ( auto mainGrid = eclipseView->eclipseCase()->eclipseCaseData()->mainGrid() )
{
auto currentGrid = mainGrid->gridByIndex( gridIndex );
if ( currentGrid && !currentGrid->isMainGrid() )
{
bool selectMainGridCell = false;
if ( currentGrid->isRadial() )
{
selectMainGridCell = !isShiftPressed;
showLgrMeshLines = !isShiftPressed;
}
else
{
selectMainGridCell = isShiftPressed;
}
if ( selectMainGridCell )
{
auto currentGrid = mainGrid->gridByIndex( gridIndex );
const auto cellIndexInMainGrid = currentGrid->cell( gridLocalCellIndex ).parentCellIndex();
if ( selectMainGridCell )
{
auto currentGrid = mainGrid->gridByIndex( gridIndex );
const auto cellIndexInMainGrid = currentGrid->cell( gridLocalCellIndex ).parentCellIndex();
// Change selection to main grid cell
gridIndex = mainGrid->gridIndex();
gridLocalCellIndex = cellIndexInMainGrid;
// Change selection to main grid cell
gridIndex = mainGrid->gridIndex();
gridLocalCellIndex = cellIndexInMainGrid;
}
}
}
}
}