From abfec0208044ec3e214c6fc534dcb510317b1e3c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Sat, 8 Aug 2026 09:21:40 +0200 Subject: [PATCH] Skip source cases without case data when computing union of active cells loadMainCaseAndActiveCellInfo() calls openAndReadActiveCellData() for each source case in a grid case group. That function returns false before setReservoirData() when the grid file is missing, and the loop only continues, so the case stays in the collection with a null eclipseCaseData(). computeUnionOfActiveCells() then iterates every reservoir and calls eclipseCaseData()->activeCellInfo() on it, which reads m_activeCellInfo off a null case data and crashes. Collect the source cases that have case data once, before the cell loops, and iterate those. This also removes the per-cell case lookup from the innermost loop. --- .../RimIdenticalGridCaseGroup.cpp | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp b/ApplicationLibCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp index 03e072c2d4..757031115a 100644 --- a/ApplicationLibCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp @@ -285,6 +285,21 @@ void RimIdenticalGridCaseGroup::computeUnionOfActiveCells() return; } + // A case that failed to open is left in the collection by loadMainCaseAndActiveCellInfo(), and has no case data. Collect the cases + // that do have data, calling activeCellInfo() on a null case data crashes. + std::vector sourceCaseData; + for ( auto* reservoir : caseCollection->reservoirs.childrenByType() ) + { + if ( reservoir && reservoir->eclipseCaseData() ) sourceCaseData.push_back( reservoir->eclipseCaseData() ); + } + + if ( sourceCaseData.empty() ) + { + clearActiveCellUnions(); + + return; + } + m_unionOfMatrixActiveCells->setReservoirCellCount( m_mainGrid->totalCellCount() ); m_unionOfFractureActiveCells->setReservoirCellCount( m_mainGrid->totalCellCount() ); m_unionOfMatrixActiveCells->setGridCount( m_mainGrid->gridCount() ); @@ -302,14 +317,13 @@ void RimIdenticalGridCaseGroup::computeUnionOfActiveCells() for ( size_t gridLocalCellIndex = 0; gridLocalCellIndex < grid->cellCount(); gridLocalCellIndex++ ) { - for ( size_t caseIdx = 0; caseIdx < caseCollection->reservoirs.size(); caseIdx++ ) + for ( size_t caseIdx = 0; caseIdx < sourceCaseData.size(); caseIdx++ ) { size_t reservoirCellIndex = grid->reservoirCellIndex( gridLocalCellIndex ); if ( activeM[gridLocalCellIndex] == 0 ) { - if ( caseCollection->reservoirs[caseIdx] - ->eclipseCaseData() + if ( sourceCaseData[caseIdx] ->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL ) ->isActive( ReservoirCellIndex( reservoirCellIndex ) ) ) { @@ -319,8 +333,7 @@ void RimIdenticalGridCaseGroup::computeUnionOfActiveCells() if ( activeF[gridLocalCellIndex] == 0 ) { - if ( caseCollection->reservoirs[caseIdx] - ->eclipseCaseData() + if ( sourceCaseData[caseIdx] ->activeCellInfo( RiaDefines::PorosityModelType::FRACTURE_MODEL ) ->isActive( ReservoirCellIndex( reservoirCellIndex ) ) ) {