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:
parent
b0f14e0c54
commit
2d8c5a7747
@ -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,14 +779,28 @@ 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())
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
std::cout << "Loading " << arguments["open"] << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
if(Client::Ref().FileExists(arguments["open"]))
|
||||
{
|
||||
try
|
||||
@ -763,14 +837,14 @@ int main(int argc, char * argv[])
|
||||
engine->g->drawrect((engine->GetWidth()/2)-100, (engine->GetHeight()/2)-25, 200, 50, 255, 255, 255, 180);
|
||||
engine->g->drawtext((engine->GetWidth()/2)-(Graphics::textwidth("Loading save...")/2), (engine->GetHeight()/2)-5, "Loading save...", style::Colour::InformationTitle.Red, style::Colour::InformationTitle.Green, style::Colour::InformationTitle.Blue, 255);
|
||||
|
||||
#ifdef OGLI
|
||||
#ifdef OGLI
|
||||
blit();
|
||||
#else
|
||||
#else
|
||||
if(engine->Scale==2)
|
||||
blit2(engine->g->vid, engine->Scale);
|
||||
else
|
||||
blit(engine->g->vid);
|
||||
#endif
|
||||
#endif
|
||||
std::string ptsaveArg = arguments["ptsave"];
|
||||
try
|
||||
{
|
||||
@ -789,9 +863,9 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
if(saveIdPart.length())
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
std::cout << "Got Ptsave: id: " << saveIdPart << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
saveId = format::StringToNumber<int>(saveIdPart);
|
||||
if(!saveId)
|
||||
throw std::runtime_error("Invalid Save ID");
|
||||
@ -819,8 +893,16 @@ int main(int argc, char * argv[])
|
||||
|
||||
EngineProcess();
|
||||
|
||||
#ifdef WIN
|
||||
#ifdef WIN
|
||||
SaveWindowPosition();
|
||||
#endif
|
||||
|
||||
#ifndef DEBUG
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
BlueScreen("Unhandled exception");
|
||||
}
|
||||
#endif
|
||||
|
||||
ui::Engine::Ref().CloseWindow();
|
||||
|
Loading…
Reference in New Issue
Block a user