From 2800f1f1891a68592ce3920e074c5a666d9a3bde Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 9 Dec 2021 09:16:41 +0100 Subject: [PATCH] #8354 RFT file open : Inconsistent data might lead to crash Use try/catch to avoid crash from RFT file reader. Avoid reading data when considering if menu items should be visible. --- .../Commands/RicWellLogTools.cpp | 25 ++++++++++++++++++- ApplicationLibCode/Commands/RicWellLogTools.h | 3 ++- .../RicAdd3dWellLogRftCurveFeature.cpp | 4 ++- .../RicNewWellLogRftCurveFeature.cpp | 2 +- .../FileInterface/RifReaderEclipseRft.cpp | 12 +++++++-- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/ApplicationLibCode/Commands/RicWellLogTools.cpp b/ApplicationLibCode/Commands/RicWellLogTools.cpp index a280b1c2c9..02ce78e04e 100644 --- a/ApplicationLibCode/Commands/RicWellLogTools.cpp +++ b/ApplicationLibCode/Commands/RicWellLogTools.cpp @@ -73,7 +73,30 @@ RimSimWellInView* RicWellLogTools::selectedSimulationWell( int* branchIndex ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RicWellLogTools::wellHasRftData( const QString& wellName ) +bool RicWellLogTools::hasRftData() +{ + RimEclipseResultCase* resultCase; + std::vector cases; + RimProject::current()->allCases( cases ); + + for ( RimCase* rimCase : cases ) + { + if ( ( resultCase = dynamic_cast( rimCase ) ) ) + { + if ( resultCase->rftReader() ) + { + return true; + } + } + } + + return false; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicWellLogTools::hasRftDataForWell( const QString& wellName ) { RimEclipseResultCase* resultCase; std::vector cases; diff --git a/ApplicationLibCode/Commands/RicWellLogTools.h b/ApplicationLibCode/Commands/RicWellLogTools.h index 791d423be5..540e514478 100644 --- a/ApplicationLibCode/Commands/RicWellLogTools.h +++ b/ApplicationLibCode/Commands/RicWellLogTools.h @@ -42,7 +42,8 @@ class RicWellLogTools { public: static RimSimWellInView* selectedSimulationWell( int* branchIndex ); - static bool wellHasRftData( const QString& wellName ); + static bool hasRftData(); + static bool hasRftDataForWell( const QString& wellName ); static bool isWellPathOrSimWellSelectedInView(); static void addWellLogChannelsToPlotTrack( RimWellLogTrack* plotTrack, const std::vector& wellLogFileChannels ); diff --git a/ApplicationLibCode/Commands/WellLogCommands/RicAdd3dWellLogRftCurveFeature.cpp b/ApplicationLibCode/Commands/WellLogCommands/RicAdd3dWellLogRftCurveFeature.cpp index 6f9b4d46ea..dea217328d 100644 --- a/ApplicationLibCode/Commands/WellLogCommands/RicAdd3dWellLogRftCurveFeature.cpp +++ b/ApplicationLibCode/Commands/WellLogCommands/RicAdd3dWellLogRftCurveFeature.cpp @@ -44,7 +44,7 @@ bool RicAdd3dWellLogRftCurveFeature::isCommandEnabled() RimWellPath* wellPath = caf::SelectionManager::instance()->selectedItemAncestorOfType(); if ( wellPath ) { - return RicWellLogTools::wellHasRftData( wellPath->name() ); + return RicWellLogTools::hasRftData(); } return false; } @@ -57,6 +57,8 @@ void RicAdd3dWellLogRftCurveFeature::onActionTriggered( bool isChecked ) RimWellPath* selectedWellPath = caf::SelectionManager::instance()->selectedItemAncestorOfType(); if ( !selectedWellPath ) return; + if ( !RicWellLogTools::hasRftDataForWell( selectedWellPath->name() ) ) return; + Rim3dWellLogRftCurve* rim3dWellLogRftCurve = new Rim3dWellLogRftCurve(); selectedWellPath->add3dWellLogCurve( rim3dWellLogRftCurve ); diff --git a/ApplicationLibCode/Commands/WellLogCommands/RicNewWellLogRftCurveFeature.cpp b/ApplicationLibCode/Commands/WellLogCommands/RicNewWellLogRftCurveFeature.cpp index 2c74d231c6..6742f2a261 100644 --- a/ApplicationLibCode/Commands/WellLogCommands/RicNewWellLogRftCurveFeature.cpp +++ b/ApplicationLibCode/Commands/WellLogCommands/RicNewWellLogRftCurveFeature.cpp @@ -59,7 +59,7 @@ bool RicNewWellLogRftCurveFeature::isCommandEnabled() if ( simulationWell != nullptr ) { - return RicWellLogTools::wellHasRftData( simulationWell->name() ); + return RicWellLogTools::hasRftData(); } return false; diff --git a/ApplicationLibCode/FileInterface/RifReaderEclipseRft.cpp b/ApplicationLibCode/FileInterface/RifReaderEclipseRft.cpp index 6b03502827..152e43c26b 100644 --- a/ApplicationLibCode/FileInterface/RifReaderEclipseRft.cpp +++ b/ApplicationLibCode/FileInterface/RifReaderEclipseRft.cpp @@ -56,11 +56,19 @@ void RifReaderEclipseRft::open() RiaLogging::info( QString( "Opening file '%1'" ).arg( m_fileName ) ); - m_ecl_rft_file = ecl_rft_file_alloc_case( RiaStringEncodingTools::toNativeEncoded( m_fileName ).data() ); + try + { + // Use try/catch, as inconsistent RFT data might lead to exceptions + // https://github.com/OPM/ResInsight/issues/8354 + m_ecl_rft_file = ecl_rft_file_alloc_case( RiaStringEncodingTools::toNativeEncoded( m_fileName ).data() ); + } + catch ( ... ) + { + } if ( m_ecl_rft_file == nullptr ) { - RiaLogging::warning( QString( "Libecl could not find/open file '%'" ).arg( m_fileName ) ); + RiaLogging::warning( QString( "Libecl could not find/open file '%1" ).arg( m_fileName ) ); return; }