From a6af4fbd005655051ced04bacb15432db26d6498 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 13 Oct 2020 11:14:47 +0200 Subject: [PATCH] #6773 Regression Test : Add more input validation due to missing files Running regression tests without valid external files revealed several crashes. Add guarding and remove asserts to make sure regression tests can be executed without crash. --- .../GridBox/RivGridBoxGenerator.cpp | 28 ++++++++++++------- .../AnalysisPlots/RimAnalysisPlot.cpp | 2 ++ .../Flow/RimFlowCharacteristicsPlot.cpp | 1 + .../Flow/RimFlowDiagSolution.cpp | 5 +++- .../Flow/RimWellPlotTools.cpp | 17 ++++++----- .../ProjectDataModel/Flow/RimWellPltPlot.cpp | 6 +++- .../ProjectDataModel/RimEclipseCase.cpp | 2 +- .../RimEclipseResultDefinition.cpp | 5 ---- .../ProjectDataModel/RimIntersection.cpp | 3 +- .../ProjectDataModel/RimSimWellInView.cpp | 5 ++++ .../ProjectDataModel/RimViewController.cpp | 2 +- .../RiaPropertyDataCommands.cpp | 2 +- 12 files changed, 50 insertions(+), 28 deletions(-) diff --git a/ApplicationCode/ModelVisualization/GridBox/RivGridBoxGenerator.cpp b/ApplicationCode/ModelVisualization/GridBox/RivGridBoxGenerator.cpp index 2fa18297a5..48ea7c6359 100644 --- a/ApplicationCode/ModelVisualization/GridBox/RivGridBoxGenerator.cpp +++ b/ApplicationCode/ModelVisualization/GridBox/RivGridBoxGenerator.cpp @@ -235,7 +235,7 @@ void RivGridBoxGenerator::updateFromCamera( const cvf::Camera* camera ) { m_gridBoxModel->removeAllParts(); - if ( m_gridBoxFaceParts.size() == 0 ) return; + if ( m_gridBoxFaceParts.empty() ) return; std::vector faceVisibility( 6, false ); for ( size_t i = POS_X; i <= NEG_Z; i++ ) @@ -263,17 +263,20 @@ void RivGridBoxGenerator::updateFromCamera( const cvf::Camera* camera ) } } - std::vector edgeVisibility( 12, false ); - computeEdgeVisibility( faceVisibility, edgeVisibility ); - - CVF_ASSERT( m_gridBoxLegendParts.size() == ( NEG_X_NEG_Y + 1 ) * 2 ); - for ( size_t i = POS_Z_POS_X; i <= NEG_X_NEG_Y; i++ ) + if ( !m_gridBoxLegendParts.empty() ) { - if ( edgeVisibility[i] ) + std::vector edgeVisibility( 12, false ); + computeEdgeVisibility( faceVisibility, edgeVisibility ); + + CVF_ASSERT( m_gridBoxLegendParts.size() == ( NEG_X_NEG_Y + 1 ) * 2 ); + for ( size_t i = POS_Z_POS_X; i <= NEG_X_NEG_Y; i++ ) { - // We have two parts for each edge - line and text - m_gridBoxModel->addPart( m_gridBoxLegendParts[2 * i].p() ); - m_gridBoxModel->addPart( m_gridBoxLegendParts[2 * i + 1].p() ); + if ( edgeVisibility[i] ) + { + // We have two parts for each edge - line and text + m_gridBoxModel->addPart( m_gridBoxLegendParts[2 * i].p() ); + m_gridBoxModel->addPart( m_gridBoxLegendParts[2 * i + 1].p() ); + } } } @@ -492,6 +495,11 @@ void RivGridBoxGenerator::createLegend( EdgeType edge, cvf::Collection RimAnalysisPlot::allAvailableTimeSteps() for ( RimSummaryCase* sumCase : timestepDefiningSourceCases() ) { + if ( !sumCase || !sumCase->summaryReader() ) continue; + const std::vector& timeSteps = sumCase->summaryReader()->timeSteps( RifEclipseSummaryAddress() ); for ( time_t t : timeSteps ) diff --git a/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp index ffd68dd9d3..b8e8ef135f 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimFlowCharacteristicsPlot.cpp @@ -650,6 +650,7 @@ void RimFlowCharacteristicsPlot::onLoadDataAndUpdate() if ( m_flowDiagSolution && m_flowCharPlotWidget ) { RigFlowDiagResults* flowResult = m_flowDiagSolution->flowDiagResults(); + if ( !flowResult ) return; { std::vector calculatedTimesteps = flowResult->calculatedTimeSteps( RigFlowDiagResultAddress::PHASE_ALL ); diff --git a/ApplicationCode/ProjectDataModel/Flow/RimFlowDiagSolution.cpp b/ApplicationCode/ProjectDataModel/Flow/RimFlowDiagSolution.cpp index 04929e1f47..497e3e5df6 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimFlowDiagSolution.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimFlowDiagSolution.cpp @@ -100,7 +100,10 @@ RigFlowDiagResults* RimFlowDiagSolution::flowDiagResults() RimEclipseResultCase* eclCase; this->firstAncestorOrThisOfType( eclCase ); - CVF_ASSERT( eclCase && eclCase->eclipseCaseData() ); + if ( !eclCase || !eclCase->eclipseCaseData() ) + { + return nullptr; + } timeStepCount = eclCase->eclipseCaseData()->results( RiaDefines::PorosityModelType::MATRIX_MODEL )->maxTimeStepCount(); diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellPlotTools.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellPlotTools.cpp index b3837a35be..195499e766 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellPlotTools.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellPlotTools.cpp @@ -555,15 +555,18 @@ std::set RimWellPlotTools::availableSimWellTimesteps( RimEclipseCase* { std::set availebleTimeSteps; - std::vector allTimeSteps = - eclCase->eclipseCaseData()->results( RiaDefines::PorosityModelType::MATRIX_MODEL )->timeStepDates(); - const RigSimWellData* simWell = eclCase->eclipseCaseData()->findSimWellData( simWellName ); - - for ( size_t tsIdx = 0; tsIdx < allTimeSteps.size(); ++tsIdx ) + if ( eclCase && eclCase->eclipseCaseData() ) { - if ( simWell->hasWellResult( tsIdx ) || ( addFirstReportTimestep && tsIdx == 0 ) ) + std::vector allTimeSteps = + eclCase->eclipseCaseData()->results( RiaDefines::PorosityModelType::MATRIX_MODEL )->timeStepDates(); + const RigSimWellData* simWell = eclCase->eclipseCaseData()->findSimWellData( simWellName ); + + for ( size_t tsIdx = 0; tsIdx < allTimeSteps.size(); ++tsIdx ) { - availebleTimeSteps.insert( allTimeSteps[tsIdx] ); + if ( simWell->hasWellResult( tsIdx ) || ( addFirstReportTimestep && tsIdx == 0 ) ) + { + availebleTimeSteps.insert( allTimeSteps[tsIdx] ); + } } } diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.cpp index 84fc27a17f..15ea03b02d 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellPltPlot.cpp @@ -157,7 +157,11 @@ void RimWellPltPlot::setPlotXAxisTitles( RimWellLogTrack* plotTrack ) std::set presentUnitSystems; for ( const RifDataSourceForRftPlt& source : m_selectedSources.v() ) { - if ( source.eclCase() ) presentUnitSystems.insert( source.eclCase()->eclipseCaseData()->unitsType() ); + if ( source.eclCase() && source.eclCase()->eclipseCaseData() ) + { + presentUnitSystems.insert( source.eclCase()->eclipseCaseData()->unitsType() ); + } + if ( source.wellLogFile() ) { if ( source.wellLogFile()->wellLogFileData() ) diff --git a/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp b/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp index 89eb75bc03..8eb71e1504 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseCase.cpp @@ -1075,7 +1075,7 @@ QString RimEclipseCase::timeStepName( int frameIdx ) const double RimEclipseCase::characteristicCellSize() const { const RigEclipseCaseData* rigEclipseCase = eclipseCaseData(); - if ( rigEclipseCase ) + if ( rigEclipseCase && rigEclipseCase->mainGrid() ) { return rigEclipseCase->mainGrid()->characteristicIJCellSize(); } diff --git a/ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp b/ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp index e50bc7b002..7d2406d9e5 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseResultDefinition.cpp @@ -1884,15 +1884,12 @@ void RimEclipseResultDefinition::updateRangesForExplicitLegends( RimRegularLegen } else { - CVF_ASSERT( rimEclipseCase ); if ( !rimEclipseCase ) return; RigEclipseCaseData* eclipseCaseData = rimEclipseCase->eclipseCaseData(); - CVF_ASSERT( eclipseCaseData ); if ( !eclipseCaseData ) return; RigCaseCellResultsData* cellResultsData = eclipseCaseData->results( this->porosityModel() ); - CVF_ASSERT( cellResultsData ); double globalMin, globalMax; double globalPosClosestToZero, globalNegClosestToZero; @@ -2039,11 +2036,9 @@ void RimEclipseResultDefinition::updateRangesForExplicitLegends( RimRegularLegen // Ternary legend update { - CVF_ASSERT( rimEclipseCase ); if ( !rimEclipseCase ) return; RigEclipseCaseData* eclipseCase = rimEclipseCase->eclipseCaseData(); - CVF_ASSERT( eclipseCase ); if ( !eclipseCase ) return; RigCaseCellResultsData* cellResultsData = eclipseCase->results( this->porosityModel() ); diff --git a/ApplicationCode/ProjectDataModel/RimIntersection.cpp b/ApplicationCode/ProjectDataModel/RimIntersection.cpp index 311474e710..dad04dd5d9 100644 --- a/ApplicationCode/ProjectDataModel/RimIntersection.cpp +++ b/ApplicationCode/ProjectDataModel/RimIntersection.cpp @@ -210,9 +210,10 @@ cvf::ref RimIntersection::createHexGridInterfac RimEclipseView* eclipseView; this->firstAncestorOrThisOfType( eclipseView ); - if ( eclipseView ) + if ( eclipseView && eclipseView->mainGrid() ) { RigMainGrid* grid = eclipseView->mainGrid(); + return new RivEclipseIntersectionGrid( grid, eclipseView->currentActiveCellInfo(), this->isInactiveCellsVisible() ); } diff --git a/ApplicationCode/ProjectDataModel/RimSimWellInView.cpp b/ApplicationCode/ProjectDataModel/RimSimWellInView.cpp index 9b98156d0f..4ebb79dec0 100644 --- a/ApplicationCode/ProjectDataModel/RimSimWellInView.cpp +++ b/ApplicationCode/ProjectDataModel/RimSimWellInView.cpp @@ -215,6 +215,11 @@ void RimSimWellInView::wellHeadTopBottomPosition( int frameIndex, cvf::Vec3d* to RimEclipseView* m_rimReservoirView; firstAncestorOrThisOfTypeAsserted( m_rimReservoirView ); + if ( !m_rimReservoirView->eclipseCase() || !m_rimReservoirView->eclipseCase()->eclipseCaseData() ) + { + return; + } + RigEclipseCaseData* rigReservoir = m_rimReservoirView->eclipseCase()->eclipseCaseData(); const RigWellResultFrame* wellResultFramePtr = nullptr; diff --git a/ApplicationCode/ProjectDataModel/RimViewController.cpp b/ApplicationCode/ProjectDataModel/RimViewController.cpp index 89db24c120..b6106da177 100644 --- a/ApplicationCode/ProjectDataModel/RimViewController.cpp +++ b/ApplicationCode/ProjectDataModel/RimViewController.cpp @@ -864,7 +864,7 @@ bool RimViewController::isRangeFilterMappingApplicable() const if ( eclipseView && geomView ) { - if ( eclipseView->eclipseCase()->eclipseCaseData() && geomView->geoMechCase() && + if ( eclipseView->eclipseCase() && eclipseView->eclipseCase()->eclipseCaseData() && geomView->geoMechCase() && geomView->geoMechCase()->geoMechData() ) { RigMainGrid* eclGrid = eclipseView->mainGrid(); diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index 3770436917..58192e5e3c 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -232,7 +232,7 @@ public: QString porosityModelName = args[4]; RimEclipseCase* rimCase = server->findReservoir( caseId ); - if ( rimCase == nullptr ) + if ( !rimCase || !rimCase->eclipseCaseData() ) { server->showErrorMessage( RiaSocketServer::tr( "ResInsight SocketServer: \n" ) + RiaSocketServer::tr( "Could not find the case with ID: \"%1\"" ).arg( caseId ) );