Do not terminate when a grid calculation reads a cell index out of range

RigAllGridCellsResultAccessor bounds checked the cell index with an assert that is compiled out in release builds, and then called std::vector::at(), which throws. RimGridCalculation::getActiveCellValues() calls the accessor from an OpenMP loop, using active cell indices from the destination case to read results from the source case, so an index beyond the source result vector threw an exception that could not escape the parallel region and called std::terminate. Return undefined for an out of range index instead, and guard against a null result accessor.
This commit is contained in:
Magne Sjaastad committed 2026-08-10 10:07:32 +02:00
1 parent dd63083c13
commit ff7bf6c7c9
4 files changed
+72 -6

No files matched your search

@@ -21,8 +21,6 @@
#include "RigGridBase.h"
#include "cafAssert.h"
#include <cmath>
//--------------------------------------------------------------------------------------------------
@@ -42,9 +40,9 @@ double RigAllGridCellsResultAccessor::cellScalar( size_t gridLocalCellIndex ) co
if ( m_reservoirResultValues->empty() ) return HUGE_VAL;
size_t reservoirCellIndex = m_grid->reservoirCellIndex( gridLocalCellIndex );
CAF_ASSERT( reservoirCellIndex < m_reservoirResultValues->size() );
if ( reservoirCellIndex >= m_reservoirResultValues->size() ) return HUGE_VAL;
return m_reservoirResultValues->at( reservoirCellIndex );
return ( *m_reservoirResultValues )[reservoirCellIndex];
}
//--------------------------------------------------------------------------------------------------
@@ -62,9 +60,11 @@ double RigAllGridCellsResultAccessor::cellScalarGlobIdx( size_t globCellIndex )
{
if ( m_reservoirResultValues->empty() ) return HUGE_VAL;
CAF_ASSERT( globCellIndex < m_reservoirResultValues->size() );
// The cell index can come from another case, see RimGridCalculation::getActiveCellValues(). Avoid at(), which throws: an
// exception escaping an OpenMP loop calls std::terminate.
if ( globCellIndex >= m_reservoirResultValues->size() ) return HUGE_VAL;
return m_reservoirResultValues->at( globCellIndex );
return ( *m_reservoirResultValues )[globCellIndex];
}
//--------------------------------------------------------------------------------------------------