From 54c7932806ddda0e457579dadd4ab4613158622f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Mon, 23 Apr 2018 16:35:19 +0200 Subject: [PATCH] Fix crashes when reading an odb file fails due to corruption --- .../RivGeoMechVizLogic.cpp | 11 +++++++++-- .../Rim3dOverlayInfoConfig.cpp | 4 +++- .../ProjectDataModel/RimCellRangeFilter.cpp | 4 ++++ .../RimGeoMechResultDefinition.cpp | 18 ++++++++++++------ .../UserInterface/RiuFemResultTextBuilder.cpp | 13 ++++++++----- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/ApplicationCode/GeoMech/GeoMechVisualization/RivGeoMechVizLogic.cpp b/ApplicationCode/GeoMech/GeoMechVisualization/RivGeoMechVizLogic.cpp index c310c17460..6e84adbc19 100644 --- a/ApplicationCode/GeoMech/GeoMechVisualization/RivGeoMechVizLogic.cpp +++ b/ApplicationCode/GeoMech/GeoMechVisualization/RivGeoMechVizLogic.cpp @@ -184,8 +184,13 @@ RivGeoMechPartMgr* RivGeoMechVizLogic::getUpdatedPartMgr(RivGeoMechPartMgrCache: } RivGeoMechPartMgr* partMgrToUpdate = m_partMgrCache->partMgr(pMgrKey); - RigGeoMechCaseData* caseData = m_geomechView->geoMechCase()->geoMechData(); - int partCount = caseData->femParts()->partCount(); + int partCount = 0; + RigGeoMechCaseData* caseData = nullptr; + if ( m_geomechView->geoMechCase() ) + { + caseData = m_geomechView->geoMechCase()->geoMechData(); + partCount = caseData->femParts()->partCount(); + } if (partMgrToUpdate->initializedFemPartCount() != partCount) { @@ -254,6 +259,8 @@ RivGeoMechPartMgr* RivGeoMechVizLogic::getUpdatedPartMgr(RivGeoMechPartMgrCache: //-------------------------------------------------------------------------------------------------- void RivGeoMechVizLogic::calculateCurrentTotalCellVisibility(cvf::UByteArray* totalVisibility, int timeStepIndex) { + if (!m_geomechView->geoMechCase()) return; + size_t gridCount = m_geomechView->geoMechCase()->geoMechData()->femParts()->partCount(); if (gridCount == 0) return; diff --git a/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp b/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp index d6b1aaff5c..a761bb0175 100644 --- a/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp +++ b/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp @@ -914,7 +914,9 @@ QString Rim3dOverlayInfoConfig::timeStepText(RimEclipseView* eclipseView) QString Rim3dOverlayInfoConfig::timeStepText(RimGeoMechView* geoMechView) { int currTimeStepIndex = geoMechView->currentTimeStep(); - QStringList timeSteps = geoMechView->geoMechCase()->timeStepStrings(); + + QStringList timeSteps; + if (geoMechView->geoMechCase()) timeSteps = geoMechView->geoMechCase()->timeStepStrings(); QString dateTimeString; if (currTimeStepIndex >= 0 && currTimeStepIndex < timeSteps.size()) diff --git a/ApplicationCode/ProjectDataModel/RimCellRangeFilter.cpp b/ApplicationCode/ProjectDataModel/RimCellRangeFilter.cpp index 82c4edc2ee..ecec2521cd 100644 --- a/ApplicationCode/ProjectDataModel/RimCellRangeFilter.cpp +++ b/ApplicationCode/ProjectDataModel/RimCellRangeFilter.cpp @@ -147,6 +147,8 @@ void RimCellRangeFilter::setDefaultValues() const cvf::StructGridInterface* grid = selectedGrid(); + if (!grid) return; + Rim3dView* rimView = nullptr; this->firstAncestorOrThisOfTypeAsserted(rimView); RigActiveCellInfo* actCellInfo = RigReservoirGridTools::activeCellInfo(rimView); @@ -208,6 +210,8 @@ void RimCellRangeFilter::defineEditorAttribute(const caf::PdmFieldHandle* field, } const cvf::StructGridInterface* grid = selectedGrid(); + + if (!grid) return; if (field == &startIndexI || field == &cellCountI) { diff --git a/ApplicationCode/ProjectDataModel/RimGeoMechResultDefinition.cpp b/ApplicationCode/ProjectDataModel/RimGeoMechResultDefinition.cpp index d96100f54a..7da009b301 100644 --- a/ApplicationCode/ProjectDataModel/RimGeoMechResultDefinition.cpp +++ b/ApplicationCode/ProjectDataModel/RimGeoMechResultDefinition.cpp @@ -139,7 +139,10 @@ void RimGeoMechResultDefinition::defineUiOrdering(QString uiConfigName, caf::Pdm if (m_compactionRefLayerUiField == (int)RigFemResultAddress::NO_COMPACTION) { - m_compactionRefLayerUiField = (int)m_geomCase->geoMechData()->femParts()->part(0)->structGrid()->reservoirIJKBoundingBox().first.z(); + if (m_geomCase && m_geomCase->geoMechData() ) + { + m_compactionRefLayerUiField = (int)m_geomCase->geoMechData()->femParts()->part(0)->structGrid()->reservoirIJKBoundingBox().first.z(); + } } } @@ -199,10 +202,13 @@ QList RimGeoMechResultDefinition::calculateValueOptions( } else if (&m_compactionRefLayerUiField == fieldNeedingOptions) { - size_t kCount = m_geomCase->geoMechData()->femParts()->part(0)->structGrid()->gridPointCountK() - 1; - for (size_t layerIdx = 0; layerIdx < kCount; ++layerIdx) + if (m_geomCase->geoMechData()) { - options.push_back(caf::PdmOptionItemInfo(QString::number(layerIdx + 1), (int)layerIdx)); + size_t kCount = m_geomCase->geoMechData()->femParts()->part(0)->structGrid()->gridPointCountK() - 1; + for ( size_t layerIdx = 0; layerIdx < kCount; ++layerIdx ) + { + options.push_back(caf::PdmOptionItemInfo(QString::number(layerIdx + 1), (int)layerIdx)); + } } } } @@ -288,7 +294,7 @@ void RimGeoMechResultDefinition::fieldChangedByUi(const caf::PdmFieldHandle* cha m_compactionRefLayer = m_compactionRefLayerUiField(); } - if (m_geomCase->geoMechData()->femPartResults()->assertResultsLoaded(this->resultAddress())) + if (m_geomCase->geoMechData() && m_geomCase->geoMechData()->femPartResults()->assertResultsLoaded(this->resultAddress())) { if (view) view->hasUserRequestedAnimation = true; } @@ -416,7 +422,7 @@ void RimGeoMechResultDefinition::initAfterRead() //-------------------------------------------------------------------------------------------------- void RimGeoMechResultDefinition::loadResult() { - if (m_geomCase) + if (m_geomCase && m_geomCase->geoMechData()) { m_geomCase->geoMechData()->femPartResults()->assertResultsLoaded(this->resultAddress()); } diff --git a/ApplicationCode/UserInterface/RiuFemResultTextBuilder.cpp b/ApplicationCode/UserInterface/RiuFemResultTextBuilder.cpp index 1157757aff..204860b147 100644 --- a/ApplicationCode/UserInterface/RiuFemResultTextBuilder.cpp +++ b/ApplicationCode/UserInterface/RiuFemResultTextBuilder.cpp @@ -215,12 +215,15 @@ QString RiuFemResultTextBuilder::formationDetails() size_t k = cvf::UNDEFINED_SIZE_T; { - RigGeoMechCaseData* geomData = m_reservoirView->geoMechCase()->geoMechData(); - if(geomData) + if ( m_reservoirView->geoMechCase() ) { - size_t i = 0; - size_t j = 0; - geomData->femParts()->part(m_gridIndex)->structGrid()->ijkFromCellIndex(m_cellIndex, &i, &j, &k); + RigGeoMechCaseData* geomData = m_reservoirView->geoMechCase()->geoMechData(); + if ( geomData ) + { + size_t i = 0; + size_t j = 0; + geomData->femParts()->part(m_gridIndex)->structGrid()->ijkFromCellIndex(m_cellIndex, &i, &j, &k); + } } }