diff --git a/stepmania/src/RageException.cpp b/stepmania/src/RageException.cpp index 839fa3baa8..802a72bc4b 100644 --- a/stepmania/src/RageException.cpp +++ b/stepmania/src/RageException.cpp @@ -2,7 +2,6 @@ #include "RageException.h" #include "RageUtil.h" #include "RageLog.h" -#include "StepMania.h" #include @@ -10,6 +9,12 @@ #include #endif +static void (*g_CleanupHandler)( const RString &sError ) = NULL; +void RageException::SetCleanupHandler( void (*pHandler)(const RString &sError) ) +{ + g_CleanupHandler = pHandler; +} + /* This is no longer actually implemented by throwing an exception, but it acts * the same way to code in practice. */ void RageException::Throw(const char *fmt, ...) @@ -42,7 +47,10 @@ void RageException::Throw(const char *fmt, ...) DebugBreak(); #endif - StepMania::HandleException( error ); + if( g_CleanupHandler != NULL ) + g_CleanupHandler( error ); + + exit(1); } /* diff --git a/stepmania/src/RageException.h b/stepmania/src/RageException.h index 0efcf03cdb..f0ec665e7d 100644 --- a/stepmania/src/RageException.h +++ b/stepmania/src/RageException.h @@ -1,4 +1,4 @@ -/* RageException - Class for thowing fatal errors. */ +/* RageException - Class for throwing fatal errors. */ #ifndef RAGE_EXCEPTION_H #define RAGE_EXCEPTION_H @@ -6,6 +6,7 @@ namespace RageException { void NORETURN Throw(const char *fmt, ...); + void SetCleanupHandler( void (*pHandler)(const RString &sError) ); }; #endif diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index c4c179d6f0..e6cdf3e7d6 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -270,9 +270,7 @@ void ShutdownGame() SAFE_DELETE( HOOKS ); } -/* Cleanly shut down, show a dialog and exit the game. We don't go back - * up the call stack, to avoid having to use exceptions. */ -void NORETURN StepMania::HandleException( RString error ) +static void HandleException( const RString &sError ) { if( g_bAutoRestart ) HOOKS->RestartProgram(); @@ -281,9 +279,7 @@ void NORETURN StepMania::HandleException( RString error ) ShutdownGame(); /* Throw up a pretty error dialog. */ - Dialog::Error( error ); - - exit(1); + Dialog::Error( sError ); } void StepMania::ResetGame() @@ -896,6 +892,7 @@ int main(int argc, char* argv[]) #endif RageThreadRegister thread( "Main thread" ); + RageException::SetCleanupHandler( HandleException ); SetCommandlineArguments( argc, argv ); diff --git a/stepmania/src/StepMania.h b/stepmania/src/StepMania.h index e4a64cf88e..408d410387 100644 --- a/stepmania/src/StepMania.h +++ b/stepmania/src/StepMania.h @@ -14,7 +14,6 @@ int main( int argc, char* argv[] ); namespace StepMania { void ApplyGraphicOptions(); - void NORETURN HandleException( CString error ); void ResetGame(); void ChangeCurrentGame( const Game* g );