From 01ce94d5391c58e12774dce0e4f1ef0df1f79a41 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 10 Jun 2026 13:09:43 +0200 Subject: [PATCH] #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(). --- .../RimCorrelationPlotCollection.cpp | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.cpp b/ApplicationLibCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.cpp index 0296bcaa10..a6e9dd7c75 100644 --- a/ApplicationLibCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlotCollection.cpp @@ -33,6 +33,27 @@ CAF_PDM_SOURCE_INIT( RimCorrelationPlotCollection, "CorrelationPlotCollection" ); +namespace +{ +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void applyBestCorrelatedParameterToCrossPlot( RimParameterResultCrossPlot* crossPlot, + RimSummaryEnsemble* ensemble, + const std::vector& 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 ); } }