diff --git a/ApplicationExeCode/RiaMain.cpp b/ApplicationExeCode/RiaMain.cpp index 7a55b2e288..17400679d8 100644 --- a/ApplicationExeCode/RiaMain.cpp +++ b/ApplicationExeCode/RiaMain.cpp @@ -39,6 +39,11 @@ #include #endif +#include + +void manageSegFailure( int signalCode ); + + RiaApplication* createApplication( int& argc, char* argv[] ) { for ( int i = 1; i < argc; ++i ) @@ -109,6 +114,10 @@ int main( int argc, char* argv[] ) QLocale::setDefault( QLocale( QLocale::English, QLocale::UnitedStates ) ); setlocale( LC_NUMERIC, "C" ); + { + signal( SIGSEGV, manageSegFailure ); + } + // Handle the command line arguments. // Todo: Move to a one-shot timer, delaying the execution until we are inside the event loop. // The complete handling of the resulting ApplicationStatus must be moved along. diff --git a/ApplicationExeCode/RiaMainTools.cpp b/ApplicationExeCode/RiaMainTools.cpp index 4a2fdcded3..624e0e4e31 100644 --- a/ApplicationExeCode/RiaMainTools.cpp +++ b/ApplicationExeCode/RiaMainTools.cpp @@ -17,6 +17,8 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RiaMainTools.h" +#include "RiaFileLogger.h" +#include "RiaLogging.h" #include "RiaRegressionTestRunner.h" #include "RiaSocketCommand.h" @@ -25,6 +27,28 @@ #include "cafPdmDefaultObjectFactory.h" #include "cafPdmUiFieldEditorHandle.h" +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void manageSegFailure( int signalCode ) +{ + auto loggers = RiaLogging::loggerInstances(); + + QString str = QString( "Segmentation fault. Signal code: %1" ).arg( signalCode ); + + for ( auto logger : loggers ) + { + if ( auto fileLogger = dynamic_cast( logger ) ) + { + fileLogger->error( str.toStdString().data() ); + + fileLogger->flush(); + } + } + + exit( 1 ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Application/Tools/RiaFileLogger.cpp b/ApplicationLibCode/Application/Tools/RiaFileLogger.cpp index cf56bdb91b..3200527fd0 100644 --- a/ApplicationLibCode/Application/Tools/RiaFileLogger.cpp +++ b/ApplicationLibCode/Application/Tools/RiaFileLogger.cpp @@ -83,6 +83,14 @@ class RiaFileLogger::Impl if ( m_spdlogger ) m_spdlogger->warn( message ); } + //-------------------------------------------------------------------------------------------------- + /// + //-------------------------------------------------------------------------------------------------- + void flush() + { + if ( m_spdlogger ) m_spdlogger->flush(); + } + private: std::shared_ptr m_spdlogger; }; @@ -150,3 +158,11 @@ void RiaFileLogger::debug( const char* message ) { m_impl->debug( message ); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaFileLogger::flush() +{ + if ( m_impl ) m_impl->flush(); +} diff --git a/ApplicationLibCode/Application/Tools/RiaFileLogger.h b/ApplicationLibCode/Application/Tools/RiaFileLogger.h index 268b0f5503..2506eb2282 100644 --- a/ApplicationLibCode/Application/Tools/RiaFileLogger.h +++ b/ApplicationLibCode/Application/Tools/RiaFileLogger.h @@ -37,6 +37,8 @@ class RiaFileLogger : public RiaLogger void info( const char* message ) override; void debug( const char* message ) override; + void flush(); + private: int m_logLevel; diff --git a/ApplicationLibCode/Commands/ApplicationCommands/RicTileWindowsFeature.cpp b/ApplicationLibCode/Commands/ApplicationCommands/RicTileWindowsFeature.cpp index 7eeb39b724..c50f255782 100644 --- a/ApplicationLibCode/Commands/ApplicationCommands/RicTileWindowsFeature.cpp +++ b/ApplicationLibCode/Commands/ApplicationCommands/RicTileWindowsFeature.cpp @@ -37,6 +37,8 @@ CAF_CMD_SOURCE_INIT( RicTileWindowsFeature, "RicTileWindowsFeature" ); //-------------------------------------------------------------------------------------------------- void RicTileWindowsFeature::applyTiling( RiuMainWindow* mainWindow, RiaDefines::WindowTileMode requestedTileMode ) { + *(int*)0 = 0; + auto mode = requestedTileMode; if ( auto proj = RimProject::current() )