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.
This commit is contained in:
Magne Sjaastad committed 2026-08-10 10:07:32 +02:00
1 parent 55fb8105e2
commit abfec02080
1 file changed
+18 -5
@@ -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<RigEclipseCaseData*> 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 ) ) )
{