TPT Blue screen of death - try its best to catch some signals (SIGSEGV) and unhandled exception in the game loop

This commit is contained in:
Simon Robertshaw 2013-05-04 21:39:43 +01:00
parent b0f14e0c54
commit 2d8c5a7747

View File

@ -624,6 +624,66 @@ bool SaveWindowPosition()
#endif
void BlueScreen(char * detailMessage){
ui::Engine * engine = &ui::Engine::Ref();
engine->g->fillrect(0, 0, engine->GetWidth(), engine->GetHeight(), 17, 114, 169, 210);
std::string errorTitle = "ERROR";
std::string errorDetails = "Details: " + std::string(detailMessage);
std::string errorHelp = "An unrecoverable fault has occured, please report the error by visiting the website below\n"
"http://" SERVER;
int currentY = 0, width, height;
int errorWidth = 0;
Graphics::textsize(errorHelp.c_str(), errorWidth, height);
engine->g->drawtext((engine->GetWidth()/2)-(errorWidth/2), ((engine->GetHeight()/2)-100) + currentY, errorTitle.c_str(), 255, 255, 255, 255);
Graphics::textsize(errorTitle.c_str(), width, height);
currentY += height + 4;
engine->g->drawtext((engine->GetWidth()/2)-(errorWidth/2), ((engine->GetHeight()/2)-100) + currentY, errorDetails.c_str(), 255, 255, 255, 255);
Graphics::textsize(errorTitle.c_str(), width, height);
currentY += height + 4;
engine->g->drawtext((engine->GetWidth()/2)-(errorWidth/2), ((engine->GetHeight()/2)-100) + currentY, errorHelp.c_str(), 255, 255, 255, 255);
Graphics::textsize(errorTitle.c_str(), width, height);
currentY += height + 4;
//Death loop
SDL_Event event;
while(true)
{
while (SDL_PollEvent(&event))
if(event.type == SDL_QUIT)
exit(-1);
#ifdef OGLI
blit();
#else
if(engine->Scale==2)
blit2(engine->g->vid, engine->Scale);
else
blit(engine->g->vid);
#endif
}
}
void SigHandler(int signal)
{
switch(signal){
case SIGSEGV:
BlueScreen("Memory read/write error");
break;
case SIGFPE:
BlueScreen("Floating point exception");
break;
case SIGILL:
BlueScreen("Program execution exception");
break;
case SIGABRT:
BlueScreen("Unexpected program abort");
break;
}
}
int main(int argc, char * argv[])
{
currentWidth = XRES+BARSIZE;
@ -719,7 +779,21 @@ int main(int argc, char * argv[])
engine->Begin(XRES+BARSIZE, YRES+MENUSIZE);
engine->SetFastQuit(Client::Ref().GetPrefBool("FastQuit", true));
GameController * gameController = new GameController();
#ifndef DEBUG
//Get ready to catch any dodgy errors
signal(SIGSEGV, SigHandler);
signal(SIGFPE, SigHandler);
signal(SIGILL, SigHandler);
signal(SIGABRT, SigHandler);
#endif
#ifndef DEBUG
GameController * gameController = NULL;
try {
#endif
gameController = new GameController();
engine->ShowWindow(gameController->GetView());
if(arguments["open"].length())
@ -823,6 +897,14 @@ int main(int argc, char * argv[])
SaveWindowPosition();
#endif
#ifndef DEBUG
}
catch(...)
{
BlueScreen("Unhandled exception");
}
#endif
ui::Engine::Ref().CloseWindow();
delete gameController;
delete ui::Engine::Ref().g;