From d28fcbfe21efbf0d472c7f34fb8db2580a61c739 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 24 Aug 2022 09:39:15 +0200 Subject: [PATCH] #9231 Contour Map: Fix crash when adding formations after a view is created --- .../Commands/RicImportFormationNamesFeature.cpp | 17 ++++++++++++----- .../RimContourMapProjection.cpp | 13 ++++++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ApplicationLibCode/Commands/RicImportFormationNamesFeature.cpp b/ApplicationLibCode/Commands/RicImportFormationNamesFeature.cpp index c4916cb28a..3ed3f64c95 100644 --- a/ApplicationLibCode/Commands/RicImportFormationNamesFeature.cpp +++ b/ApplicationLibCode/Commands/RicImportFormationNamesFeature.cpp @@ -33,11 +33,13 @@ #include "RimColorLegendItem.h" #include "RimEclipseCase.h" #include "RimEclipseCellColors.h" +#include "RimEclipseContourMapView.h" #include "RimEclipseView.h" #include "RimFormationNames.h" #include "RimFormationNamesCollection.h" #include "RimGeoMechCase.h" #include "RimGeoMechCellColors.h" +#include "RimGeoMechContourMapView.h" #include "RimGeoMechView.h" #include "RimOilField.h" #include "RimProject.h" @@ -189,12 +191,12 @@ void RicImportFormationNamesFeature::addCustomColorLegend( QString& name, RimFor // return if no formation names or colors (latter e.g. in case of FMU input or LYR without colors) if ( formationNames.empty() || formationColors.empty() ) return; - RimColorLegend* colorLegend = new RimColorLegend; + auto* colorLegend = new RimColorLegend; colorLegend->setColorLegendName( name ); for ( size_t i = 0; i < formationColors.size(); i++ ) { - RimColorLegendItem* colorLegendItem = new RimColorLegendItem; + auto* colorLegendItem = new RimColorLegendItem; colorLegendItem->setValues( formationNames[i], (int)i, formationColors[i] ); @@ -214,9 +216,14 @@ void RicImportFormationNamesFeature::addCustomColorLegend( QString& name, RimFor //-------------------------------------------------------------------------------------------------- void RicImportFormationNamesFeature::setFormationCellResultAndLegend( Rim3dView* activeView, QString& legendName ) { - RimRegularLegendConfig* legendConfig = nullptr; + auto eclipseContourMapView = dynamic_cast( activeView ); + if ( eclipseContourMapView ) return; - RimEclipseView* eclView = dynamic_cast( activeView ); + auto geoMechContourMapView = dynamic_cast( activeView ); + if ( geoMechContourMapView ) return; + + RimRegularLegendConfig* legendConfig = nullptr; + auto* eclView = dynamic_cast( activeView ); if ( eclView ) { eclView->cellResult()->setResultType( RiaDefines::ResultCatType::FORMATION_NAMES ); @@ -229,7 +236,7 @@ void RicImportFormationNamesFeature::setFormationCellResultAndLegend( Rim3dView* eclView->updateAllRequiredEditors(); } - RimGeoMechView* geoMechView = dynamic_cast( activeView ); + auto* geoMechView = dynamic_cast( activeView ); if ( geoMechView ) { legendConfig = geoMechView->cellResult()->legendConfig(); diff --git a/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp b/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp index 59fa0d1289..3d01ad7307 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp @@ -1027,9 +1027,16 @@ void RimContourMapProjection::generateTrianglesWithVertexValues() } } } - threadTriangles[myThread][c].insert( threadTriangles[myThread][c].end(), - clippedTriangles.begin(), - clippedTriangles.end() ); + + { + // Add critical section here due to a weird bug when running in a single thread + // Running multi threaded does not require this critical section, as we use a thread local data + // structure +#pragma omp critical + threadTriangles[myThread][c].insert( threadTriangles[myThread][c].end(), + clippedTriangles.begin(), + clippedTriangles.end() ); + } } } }