mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-17 22:38:38 +01:00
Don't show a blue screen when the window is already closing
This commit is contained in:
parent
04455ada1c
commit
f805b15ee5
@ -123,22 +123,30 @@ void BlueScreen(String detailMessage)
|
||||
}
|
||||
}
|
||||
|
||||
struct
|
||||
{
|
||||
int sig;
|
||||
const char *message;
|
||||
} signalMessages[] = {
|
||||
{ SIGSEGV, "Memory read/write error" },
|
||||
{ SIGFPE, "Floating point exception" },
|
||||
{ SIGILL, "Program execution exception" },
|
||||
{ SIGABRT, "Unexpected program abort" },
|
||||
{ 0, nullptr },
|
||||
};
|
||||
|
||||
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;
|
||||
const char *message = "Unknown signal";
|
||||
for (auto *msg = signalMessages; msg->message; ++msg)
|
||||
{
|
||||
if (msg->sig == signal)
|
||||
{
|
||||
message = msg->message;
|
||||
break;
|
||||
}
|
||||
}
|
||||
BlueScreen(ByteString(message).FromUtf8());
|
||||
}
|
||||
|
||||
constexpr int SCALE_MAXIMUM = 10;
|
||||
@ -176,6 +184,11 @@ int main(int argc, char * argv[])
|
||||
{
|
||||
Platform::SetupCrt();
|
||||
Platform::Atexit([]() {
|
||||
// Unregister dodgy error handlers so they don't try to show the blue screen when the window is closed
|
||||
for (auto *msg = signalMessages; msg->message; ++msg)
|
||||
{
|
||||
signal(msg->sig, SIG_DFL);
|
||||
}
|
||||
SDLClose();
|
||||
explicitSingletons.reset();
|
||||
});
|
||||
@ -381,10 +394,10 @@ int main(int argc, char * argv[])
|
||||
if (enableBluescreen)
|
||||
{
|
||||
//Get ready to catch any dodgy errors
|
||||
signal(SIGSEGV, SigHandler);
|
||||
signal(SIGFPE, SigHandler);
|
||||
signal(SIGILL, SigHandler);
|
||||
signal(SIGABRT, SigHandler);
|
||||
for (auto *msg = signalMessages; msg->message; ++msg)
|
||||
{
|
||||
signal(msg->sig, SigHandler);
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (X86)
|
||||
|
Loading…
x
Reference in New Issue
Block a user