From 85f5848bde35a676c4045b21001df77939b22006 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 4 Jun 2026 13:49:56 +0200 Subject: [PATCH] #14112 Contour map: guard remaining legend config dereferences Guard the remaining unguarded legendConfig() uses so a null legend config cannot crash: both updateLegend() implementations (eclipse and statistics projections) now capture the pointer and return early when null, and the statistics view tree ordering skips a null legend config. --- .../ContourMap/RimEclipseContourMapProjection.cpp | 9 ++++++--- .../ContourMap/RimStatisticsContourMapProjection.cpp | 9 ++++++--- .../ContourMap/RimStatisticsContourMapView.cpp | 5 ++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/ContourMap/RimEclipseContourMapProjection.cpp b/ApplicationLibCode/ProjectDataModel/ContourMap/RimEclipseContourMapProjection.cpp index 8b13178b4b..ff4f9f7df4 100644 --- a/ApplicationLibCode/ProjectDataModel/ContourMap/RimEclipseContourMapProjection.cpp +++ b/ApplicationLibCode/ProjectDataModel/ContourMap/RimEclipseContourMapProjection.cpp @@ -112,6 +112,9 @@ RimRegularLegendConfig* RimEclipseContourMapProjection::legendConfig() const //-------------------------------------------------------------------------------------------------- void RimEclipseContourMapProjection::updateLegend() { + RimRegularLegendConfig* legend = legendConfig(); + if ( !legend ) return; + RimEclipseCellColors* cellColors = view()->cellResult(); auto [minValAllTimeSteps, maxValAllTimeSteps] = minmaxValuesAllTimeSteps(); @@ -119,11 +122,11 @@ void RimEclipseContourMapProjection::updateLegend() double minVal = m_contourMapProjection ? m_contourMapProjection->minValue() : std::numeric_limits::infinity(); double maxVal = m_contourMapProjection ? m_contourMapProjection->maxValue() : -std::numeric_limits::infinity(); - legendConfig()->setAutomaticRanges( minValAllTimeSteps, maxValAllTimeSteps, minVal, maxVal ); + legend->setAutomaticRanges( minValAllTimeSteps, maxValAllTimeSteps, minVal, maxVal ); if ( isColumnResult() ) { - legendConfig()->setTitle( QString( "Map Projection\n%1" ).arg( m_resultAggregation().uiText() ) ); + legend->setTitle( QString( "Map Projection\n%1" ).arg( m_resultAggregation().uiText() ) ); } else { @@ -134,7 +137,7 @@ void RimEclipseContourMapProjection::updateLegend() } projectionLegendText += QString( "\nResult: %1" ).arg( cellColors->resultVariableUiShortName() ); - legendConfig()->setTitle( projectionLegendText ); + legend->setTitle( projectionLegendText ); } } diff --git a/ApplicationLibCode/ProjectDataModel/ContourMap/RimStatisticsContourMapProjection.cpp b/ApplicationLibCode/ProjectDataModel/ContourMap/RimStatisticsContourMapProjection.cpp index 587cd51f69..300de441a9 100644 --- a/ApplicationLibCode/ProjectDataModel/ContourMap/RimStatisticsContourMapProjection.cpp +++ b/ApplicationLibCode/ProjectDataModel/ContourMap/RimStatisticsContourMapProjection.cpp @@ -112,23 +112,26 @@ RimRegularLegendConfig* RimStatisticsContourMapProjection::legendConfig() const //-------------------------------------------------------------------------------------------------- void RimStatisticsContourMapProjection::updateLegend() { + RimRegularLegendConfig* legend = legendConfig(); + if ( !legend ) return; + auto [minValAllTimeSteps, maxValAllTimeSteps] = minmaxValuesAllTimeSteps(); double minVal = m_contourMapProjection ? m_contourMapProjection->minValue() : std::numeric_limits::infinity(); double maxVal = m_contourMapProjection ? m_contourMapProjection->maxValue() : -std::numeric_limits::infinity(); - legendConfig()->setAutomaticRanges( minValAllTimeSteps, maxValAllTimeSteps, minVal, maxVal ); + legend->setAutomaticRanges( minValAllTimeSteps, maxValAllTimeSteps, minVal, maxVal ); if ( statisticsContourMap()->isColumnResult() ) { - legendConfig()->setTitle( QString( "Map Projection\n%1" ).arg( resultVariableName() ) ); + legend->setTitle( QString( "Map Projection\n%1" ).arg( resultVariableName() ) ); } else { QString projectionLegendText = QString( "Map Projection\n%1" ).arg( resultAggregationText() ); projectionLegendText += QString( "\nResult: %1" ).arg( resultVariableName() ); - legendConfig()->setTitle( projectionLegendText ); + legend->setTitle( projectionLegendText ); } } diff --git a/ApplicationLibCode/ProjectDataModel/ContourMap/RimStatisticsContourMapView.cpp b/ApplicationLibCode/ProjectDataModel/ContourMap/RimStatisticsContourMapView.cpp index fad76ecca4..fba3742740 100644 --- a/ApplicationLibCode/ProjectDataModel/ContourMap/RimStatisticsContourMapView.cpp +++ b/ApplicationLibCode/ProjectDataModel/ContourMap/RimStatisticsContourMapView.cpp @@ -155,7 +155,10 @@ void RimStatisticsContourMapView::defineUiTreeOrdering( caf::PdmUiTreeOrdering& { uiTreeOrdering.add( m_overlayInfoConfig() ); uiTreeOrdering.add( m_contourMapProjection ); - uiTreeOrdering.add( cellResult()->legendConfig() ); + if ( cellResult() && cellResult()->legendConfig() ) + { + uiTreeOrdering.add( cellResult()->legendConfig() ); + } uiTreeOrdering.add( wellCollection() ); uiTreeOrdering.add( faultCollection() ); uiTreeOrdering.add( annotationCollection() );