#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.
This commit is contained in:
Magne Sjaastad 2021-12-09 09:16:41 +01:00
parent f028491bb9
commit 2800f1f189
5 changed files with 40 additions and 6 deletions

View File

@ -73,7 +73,30 @@ RimSimWellInView* RicWellLogTools::selectedSimulationWell( int* branchIndex )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicWellLogTools::wellHasRftData( const QString& wellName )
bool RicWellLogTools::hasRftData()
{
RimEclipseResultCase* resultCase;
std::vector<RimCase*> cases;
RimProject::current()->allCases( cases );
for ( RimCase* rimCase : cases )
{
if ( ( resultCase = dynamic_cast<RimEclipseResultCase*>( rimCase ) ) )
{
if ( resultCase->rftReader() )
{
return true;
}
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicWellLogTools::hasRftDataForWell( const QString& wellName )
{
RimEclipseResultCase* resultCase;
std::vector<RimCase*> cases;

View File

@ -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<RimWellLogFileChannel*>& wellLogFileChannels );

View File

@ -44,7 +44,7 @@ bool RicAdd3dWellLogRftCurveFeature::isCommandEnabled()
RimWellPath* wellPath = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellPath>();
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<RimWellPath>();
if ( !selectedWellPath ) return;
if ( !RicWellLogTools::hasRftDataForWell( selectedWellPath->name() ) ) return;
Rim3dWellLogRftCurve* rim3dWellLogRftCurve = new Rim3dWellLogRftCurve();
selectedWellPath->add3dWellLogCurve( rim3dWellLogRftCurve );

View File

@ -59,7 +59,7 @@ bool RicNewWellLogRftCurveFeature::isCommandEnabled()
if ( simulationWell != nullptr )
{
return RicWellLogTools::wellHasRftData( simulationWell->name() );
return RicWellLogTools::hasRftData();
}
return false;

View File

@ -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;
}