implement RageException::Throw without actually using exceptions
This commit is contained in:
@@ -2,10 +2,10 @@
|
|||||||
#include "RageException.h"
|
#include "RageException.h"
|
||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
#include "RageLog.h"
|
#include "StepMania.h"
|
||||||
|
|
||||||
#if defined(_WINDOWS) && defined(DEBUG)
|
#if defined(_WINDOWS) && defined(DEBUG)
|
||||||
#include "windows.h"
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
RageException::RageException( const CString &str ):
|
RageException::RageException( const CString &str ):
|
||||||
@@ -18,6 +18,8 @@ const char* RageException::what() const throw ()
|
|||||||
return m_sError;
|
return m_sError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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, ...)
|
void RageException::Throw(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
@@ -47,7 +49,7 @@ void RageException::Throw(const char *fmt, ...)
|
|||||||
DebugBreak();
|
DebugBreak();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
throw RageException( error );
|
HandleException( error );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageException::ThrowNonfatal(const char *fmt, ...)
|
void RageException::ThrowNonfatal(const char *fmt, ...)
|
||||||
|
|||||||
+56
-59
@@ -161,12 +161,66 @@ void ApplyGraphicOptions()
|
|||||||
INPUTMAN->WindowReset();
|
INPUTMAN->WindowReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Shutdown all global singletons. Note that this may be called partway through
|
||||||
|
* initialization, due to an object failing to initialize, in which case some of
|
||||||
|
* these may still be NULL. */
|
||||||
|
void ShutdownGame()
|
||||||
|
{
|
||||||
|
/* First, tell SOUND that we're shutting down. This signals sound drivers to
|
||||||
|
* stop sounds, which we want to do before any threads that may have started sounds
|
||||||
|
* are closed; this prevents annoying DirectSound glitches and delays. */
|
||||||
|
if( SOUNDMAN )
|
||||||
|
SOUNDMAN->Shutdown();
|
||||||
|
|
||||||
|
SAFE_DELETE( SCREENMAN );
|
||||||
|
SAFE_DELETE( NSMAN );
|
||||||
|
/* Delete INPUTMAN before the other INPUTFILTER handlers, or an input
|
||||||
|
* driver may try to send a message to INPUTFILTER after we delete it. */
|
||||||
|
SAFE_DELETE( INPUTMAN );
|
||||||
|
SAFE_DELETE( INPUTQUEUE );
|
||||||
|
SAFE_DELETE( INPUTMAPPER );
|
||||||
|
SAFE_DELETE( INPUTFILTER );
|
||||||
|
SAFE_DELETE( MODELMAN );
|
||||||
|
SAFE_DELETE( PROFILEMAN ); // PROFILEMAN needs the songs still loaded
|
||||||
|
SAFE_DELETE( UNLOCKMAN );
|
||||||
|
SAFE_DELETE( CRYPTMAN );
|
||||||
|
SAFE_DELETE( MEMCARDMAN );
|
||||||
|
SAFE_DELETE( SONGMAN );
|
||||||
|
SAFE_DELETE( BANNERCACHE );
|
||||||
|
SAFE_DELETE( SONGINDEX );
|
||||||
|
SAFE_DELETE( SOUND ); /* uses GAMESTATE, PREFSMAN */
|
||||||
|
SAFE_DELETE( PREFSMAN );
|
||||||
|
SAFE_DELETE( GAMESTATE );
|
||||||
|
SAFE_DELETE( GAMEMAN );
|
||||||
|
SAFE_DELETE( NOTESKIN );
|
||||||
|
SAFE_DELETE( THEME );
|
||||||
|
SAFE_DELETE( ANNOUNCER );
|
||||||
|
SAFE_DELETE( BOOKKEEPER );
|
||||||
|
SAFE_DELETE( LIGHTSMAN );
|
||||||
|
SAFE_DELETE( SOUNDMAN );
|
||||||
|
SAFE_DELETE( FONT );
|
||||||
|
SAFE_DELETE( TEXTUREMAN );
|
||||||
|
SAFE_DELETE( DISPLAY );
|
||||||
|
Dialog::Shutdown();
|
||||||
|
SAFE_DELETE( LOG );
|
||||||
|
SAFE_DELETE( FILEMAN );
|
||||||
|
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 HandleException( CString error )
|
void HandleException( CString error )
|
||||||
{
|
{
|
||||||
|
/* Shut down first, so we exit graphics mode before trying to open a dialog. */
|
||||||
|
ShutdownGame();
|
||||||
|
|
||||||
if( g_bAutoRestart )
|
if( g_bAutoRestart )
|
||||||
HOOKS->RestartProgram();
|
HOOKS->RestartProgram();
|
||||||
|
|
||||||
Dialog::Error( error ); // throw up a pretty error dialog
|
/* Throw up a pretty error dialog. */
|
||||||
|
Dialog::Error( error );
|
||||||
|
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExitGame()
|
void ExitGame()
|
||||||
@@ -938,12 +992,7 @@ int main(int argc, char* argv[])
|
|||||||
/* Set up arch hooks first. This may set up crash handling. */
|
/* Set up arch hooks first. This may set up crash handling. */
|
||||||
HOOKS = MakeArchHooks();
|
HOOKS = MakeArchHooks();
|
||||||
|
|
||||||
CString g_sErrorString = "";
|
|
||||||
#if !defined(DEBUG)
|
#if !defined(DEBUG)
|
||||||
/* Always catch RageExceptions; they should always have distinct strings. */
|
|
||||||
|
|
||||||
try { /* RageException */
|
|
||||||
|
|
||||||
/* Tricky: for other exceptions, we want a backtrace. To do this in Windows,
|
/* Tricky: for other exceptions, we want a backtrace. To do this in Windows,
|
||||||
* we need to catch the exception and force a crash. The call stack is still
|
* we need to catch the exception and force a crash. The call stack is still
|
||||||
* there, and gets picked up by the crash handler. (If we don't catch it, we'll
|
* there, and gets picked up by the crash handler. (If we don't catch it, we'll
|
||||||
@@ -1141,53 +1190,7 @@ int main(int argc, char* argv[])
|
|||||||
PREFSMAN->SaveGlobalPrefsToDisk();
|
PREFSMAN->SaveGlobalPrefsToDisk();
|
||||||
SaveGamePrefsToDisk();
|
SaveGamePrefsToDisk();
|
||||||
|
|
||||||
#if !defined(DEBUG)
|
ShutdownGame();
|
||||||
}
|
|
||||||
catch( const RageException &e )
|
|
||||||
{
|
|
||||||
/* Gracefully shut down. */
|
|
||||||
g_sErrorString = e.what();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* First, tell SOUND that we're shutting down. This signals sound drivers to
|
|
||||||
* stop sounds, which we want to do before any threads that may have started sounds
|
|
||||||
* are closed; this prevents annoying DirectSound glitches and delays. */
|
|
||||||
if( SOUNDMAN )
|
|
||||||
SOUNDMAN->Shutdown();
|
|
||||||
|
|
||||||
SAFE_DELETE( SCREENMAN );
|
|
||||||
SAFE_DELETE( NSMAN );
|
|
||||||
/* Delete INPUTMAN before the other INPUTFILTER handlers, or an input
|
|
||||||
* driver may try to send a message to INPUTFILTER after we delete it. */
|
|
||||||
SAFE_DELETE( INPUTMAN );
|
|
||||||
SAFE_DELETE( INPUTQUEUE );
|
|
||||||
SAFE_DELETE( INPUTMAPPER );
|
|
||||||
SAFE_DELETE( INPUTFILTER );
|
|
||||||
SAFE_DELETE( MODELMAN );
|
|
||||||
SAFE_DELETE( PROFILEMAN ); // PROFILEMAN needs the songs still loaded
|
|
||||||
SAFE_DELETE( UNLOCKMAN );
|
|
||||||
SAFE_DELETE( CRYPTMAN );
|
|
||||||
SAFE_DELETE( MEMCARDMAN );
|
|
||||||
SAFE_DELETE( SONGMAN );
|
|
||||||
SAFE_DELETE( BANNERCACHE );
|
|
||||||
SAFE_DELETE( SONGINDEX );
|
|
||||||
SAFE_DELETE( SOUND ); /* uses GAMESTATE, PREFSMAN */
|
|
||||||
SAFE_DELETE( PREFSMAN );
|
|
||||||
SAFE_DELETE( GAMESTATE );
|
|
||||||
SAFE_DELETE( GAMEMAN );
|
|
||||||
SAFE_DELETE( NOTESKIN );
|
|
||||||
SAFE_DELETE( THEME );
|
|
||||||
SAFE_DELETE( ANNOUNCER );
|
|
||||||
SAFE_DELETE( BOOKKEEPER );
|
|
||||||
SAFE_DELETE( LIGHTSMAN );
|
|
||||||
SAFE_DELETE( SOUNDMAN );
|
|
||||||
SAFE_DELETE( FONT );
|
|
||||||
SAFE_DELETE( TEXTUREMAN );
|
|
||||||
SAFE_DELETE( DISPLAY );
|
|
||||||
Dialog::Shutdown();
|
|
||||||
SAFE_DELETE( LOG );
|
|
||||||
SAFE_DELETE( FILEMAN );
|
|
||||||
|
|
||||||
#if !defined(DEBUG) && defined(_WINDOWS)
|
#if !defined(DEBUG) && defined(_WINDOWS)
|
||||||
}
|
}
|
||||||
@@ -1200,14 +1203,8 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( g_sErrorString != "" )
|
|
||||||
HandleException( g_sErrorString );
|
|
||||||
|
|
||||||
SAFE_DELETE( HOOKS );
|
|
||||||
|
|
||||||
#ifndef _XBOX
|
#ifndef _XBOX
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ void __cdecl main();
|
|||||||
int main( int argc, char* argv[] );
|
int main( int argc, char* argv[] );
|
||||||
#endif
|
#endif
|
||||||
void ApplyGraphicOptions();
|
void ApplyGraphicOptions();
|
||||||
void HandleException( CString error );
|
void NORETURN HandleException( CString error );
|
||||||
void ExitGame();
|
void ExitGame();
|
||||||
void ResetGame( bool ReturnToFirstScreen=true );
|
void ResetGame( bool ReturnToFirstScreen=true );
|
||||||
void ReadGamePrefsFromDisk( bool bSwitchToLastPlayedGame=true );
|
void ReadGamePrefsFromDisk( bool bSwitchToLastPlayedGame=true );
|
||||||
|
|||||||
Reference in New Issue
Block a user