#14174 Fix crash when creating Correlation Report Plot

Guard against empty curve definitions and time steps in
RimCorrelationPlotCollection. When the first ensemble has no FOPT
summary vector, the tornado/cross-plot curve definition vector was
empty and calling .front() on it dereferenced invalid memory,
causing a segfault in RiaSummaryCurveDefinition::summaryAddressY().
This commit is contained in:
Magne Sjaastad authored and GitHub committed 2026-06-10 13:09:43 +02:00
1 parent 63a1dc2b35
commit 01ce94d539
1 file changed
+27 -12
@@ -33,6 +33,27 @@
CAF_PDM_SOURCE_INIT( RimCorrelationPlotCollection, "CorrelationPlotCollection" );
namespace
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void applyBestCorrelatedParameterToCrossPlot( RimParameterResultCrossPlot* crossPlot,
RimSummaryEnsemble* ensemble,
const std::vector<RiaSummaryCurveDefinition>& curveDefsTornadoAndCrossPlot,
std::time_t timeStep )
{
if ( curveDefsTornadoAndCrossPlot.empty() ) return;
auto correlationSortedEnsembleParameters =
ensemble->correlationSortedEnsembleParameters( curveDefsTornadoAndCrossPlot.front().summaryAddressY(), timeStep );
if ( correlationSortedEnsembleParameters.empty() ) return;
QString crossPlotEnsembleParameterName = correlationSortedEnsembleParameters.front().first.name;
crossPlot->setEnsembleParameter( crossPlotEnsembleParameterName );
}
} // namespace
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -371,14 +392,11 @@ void RimCorrelationPlotCollection::applyFirstEnsembleFieldAddressesToReport( Rim
plot->correlationPlot()->setCurveDefinitions( curveDefsTornadoAndCrossPlot );
plot->crossPlot()->setCurveDefinitions( curveDefsTornadoAndCrossPlot );
time_t timeStep = *( plot->matrixPlot()->allAvailableTimeSteps().rbegin() );
auto correlationSortedEnsembleParameters =
ensembles.front()->correlationSortedEnsembleParameters( curveDefsTornadoAndCrossPlot.front().summaryAddressY(), timeStep );
if ( !correlationSortedEnsembleParameters.empty() )
{
QString crossPlotEnsembleParameterName = correlationSortedEnsembleParameters.front().first.name;
plot->crossPlot()->setEnsembleParameter( crossPlotEnsembleParameterName );
}
auto availableTimeSteps = plot->matrixPlot()->allAvailableTimeSteps();
if ( availableTimeSteps.empty() ) return;
time_t timeStep = *( availableTimeSteps.rbegin() );
applyBestCorrelatedParameterToCrossPlot( plot->crossPlot(), ensembles.front(), curveDefsTornadoAndCrossPlot, timeStep );
plot->matrixPlot()->setTimeStep( timeStep );
}
}
@@ -418,10 +436,7 @@ void RimCorrelationPlotCollection::applyEnsembleFieldAndTimeStepToReport( RimCor
plot->crossPlot()->setCurveDefinitions( curveDefsTornadoAndCrossPlot );
plot->crossPlot()->setTimeStep( timeStep );
auto correlationSortedEnsembleParameters =
ensemble->correlationSortedEnsembleParameters( curveDefsTornadoAndCrossPlot.front().summaryAddressY(), timeStep );
QString crossPlotEnsembleParameterName = correlationSortedEnsembleParameters.front().first.name;
plot->crossPlot()->setEnsembleParameter( crossPlotEnsembleParameterName );
applyBestCorrelatedParameterToCrossPlot( plot->crossPlot(), ensemble, curveDefsTornadoAndCrossPlot, timeStep );
}
}