Replace AssertFatal with throw FatalAssert()
by Tim Hutcheson · in Torque Game Engine · 04/27/2006 (9:28 am) · 1 replies
I just added a handy construct that provides a little more information when running the engine in Release mode and a fatal error occurs that crashes the engine. This typically locks up the cursor as well and requires a Task Manager intervention. The usual way to to debug this is to rerun the app in Debug mode and look for AssertFatal to catch the error. Problem is it doesn't always work well due to sluggish behavior when in debug and at times the error is hard to reproduce because of this.
So I made the following change in platformAssert.h.
At about line 50, just before #ifdef TORQUE_ENABLE_ASSERTS add:
Further down about line 80, where if says
change the AssertFatal statement to:
One can sprinkle variations of more specific catch statements elsewhere in the code to provide much more information by modifying the text in the printf.
Run the app with the dos box console active (-console cmd line parameter).
When my bug occurs, I now get the following in the dos console and don't lose control.
I still have no idea how to fix the bug but now I can drive about until it happens and not crash. :-)
So I made the following change in platformAssert.h.
At about line 50, just before #ifdef TORQUE_ENABLE_ASSERTS add:
struct FatalAssert { const char *p; FatalAssert( const char *q) { p = q; } };Further down about line 80, where if says
#define AssertWarn(x, y) {}
#define AssertFatal(x, y) { }change the AssertFatal statement to:
#define AssertFatal(x, y) { if((bool)(x)==(bool)0) throw FatalAssert(y); }In main.cc, at around line 500, DemoGame::main(int argc, const char **argv), make the following change, just to see how this might be used tocatch errors.while(Game->isRunning())
{
PROFILE_START(MainLoop);
try {
Game->journalProcess();
Net::process();
Platform::process();
TelConsole->process();
TelDebugger->process();
TimeManager::process();
}
catch (FatalAssert e )
{
Con::printf( "AssertFatal: %s", e.p );
}
}One can sprinkle variations of more specific catch statements elsewhere in the code to provide much more information by modifying the text in the printf.
Run the app with the dos box console active (-console cmd line parameter).
When my bug occurs, I now get the following in the dos console and don't lose control.
AssertFatal: Bad world box! AssertFatal: Bad world box!
I still have no idea how to fix the bug but now I can drive about until it happens and not crash. :-)
About the author
Torque Owner Tim Hutcheson
#define AssertFatal(x, y) \ {\ if((bool)(x)==(bool)0) \ { \ char *t = new char[256]; \ dSprintf(t,sizeof(t),"%s(%d): %s", __FILE__,__LINE__,y);\ throw FatalAssert(t);\ } \ }