Avoid crash when adding a grid case multiple times

This commit is contained in:
Magne Sjaastad 2022-10-04 18:43:36 +02:00 committed by GitHub
parent 179e269fcc
commit 4a673b7cd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View File

@ -115,8 +115,10 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList&
project->activeOilField() ? project->activeOilField()->summaryCaseMainCollection() : nullptr; project->activeOilField() ? project->activeOilField()->summaryCaseMainCollection() : nullptr;
if ( sumCaseColl ) if ( sumCaseColl )
{ {
std::vector<RimSummaryCase*> newSumCases = sumCaseColl->createSummaryCasesFromFileInfos( summaryFileInfos ); std::vector<RimSummaryCase*> candidateCases = sumCaseColl->createSummaryCasesFromFileInfos( summaryFileInfos );
for ( RimSummaryCase* newSumCase : newSumCases ) std::vector<RimSummaryCase*> duplicatedCases;
for ( RimSummaryCase* newSumCase : candidateCases )
{ {
RimSummaryCaseCollection* existingCollection = nullptr; RimSummaryCaseCollection* existingCollection = nullptr;
QString gridCaseFile = QString gridCaseFile =
@ -130,7 +132,7 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList&
auto* existingFileSummaryCase = dynamic_cast<RimFileSummaryCase*>( existingSummaryCase ); auto* existingFileSummaryCase = dynamic_cast<RimFileSummaryCase*>( existingSummaryCase );
if ( existingGridSummaryCase ) if ( existingGridSummaryCase )
{ {
delete newSumCase; // No need to add anything new. Already have one. duplicatedCases.push_back( newSumCase );
continue; continue;
} }
else if ( existingFileSummaryCase ) else if ( existingFileSummaryCase )
@ -183,7 +185,8 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList&
// Remove existing case // Remove existing case
sumCaseColl->removeCase( existingFileSummaryCase ); sumCaseColl->removeCase( existingFileSummaryCase );
delete existingFileSummaryCase;
duplicatedCases.push_back( existingFileSummaryCase );
} }
} }
if ( existingCollection ) if ( existingCollection )
@ -197,10 +200,18 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList&
sumCaseColl->updateAllRequiredEditors(); sumCaseColl->updateAllRequiredEditors();
} }
if ( !newSumCases.empty() ) // Delete cases that already was present
for ( auto duplicateCase : duplicatedCases )
{ {
RicSummaryPlotBuilder::createAndAppendDefaultSummaryMultiPlot( { newSumCases.front() }, {} ); candidateCases.erase( std::remove( candidateCases.begin(), candidateCases.end(), duplicateCase ),
RiuPlotMainWindowTools::setExpanded( newSumCases.front() ); candidateCases.end() );
delete duplicateCase;
}
if ( !candidateCases.empty() )
{
RicSummaryPlotBuilder::createAndAppendDefaultSummaryMultiPlot( { candidateCases.front() }, {} );
RiuPlotMainWindowTools::setExpanded( candidateCases.front() );
} }
} }
} }

View File

@ -220,3 +220,11 @@ def test_selected_cells(rips_instance, initialize_test):
# Try to read for SOIL the time step (will be empty since nothing is selected) # Try to read for SOIL the time step (will be empty since nothing is selected)
soil_results = case.selected_cell_property("DYNAMIC_NATIVE", "SOIL", tidx) soil_results = case.selected_cell_property("DYNAMIC_NATIVE", "SOIL", tidx)
assert len(soil_results) == 0 assert len(soil_results) == 0
def test_multiple_load_of_same_case(rips_instance, initialize_test):
# Test related to issue https://github.com/OPM/ResInsight/issues/9332
path_name = dataroot.PATH + "/flow_diagnostics_test/SIMPLE_SUMMARY2.EGRID"
case_count = 3
for i in range(case_count):
case = rips_instance.project.load_case(path_name)