mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-23 00:12:51 +02:00
Don't show a blue screen when the window is already closing
This commit is contained in:
@@ -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)
|
void SigHandler(int signal)
|
||||||
{
|
{
|
||||||
switch(signal){
|
const char *message = "Unknown signal";
|
||||||
case SIGSEGV:
|
for (auto *msg = signalMessages; msg->message; ++msg)
|
||||||
BlueScreen("Memory read/write error");
|
{
|
||||||
break;
|
if (msg->sig == signal)
|
||||||
case SIGFPE:
|
{
|
||||||
BlueScreen("Floating point exception");
|
message = msg->message;
|
||||||
break;
|
break;
|
||||||
case SIGILL:
|
}
|
||||||
BlueScreen("Program execution exception");
|
|
||||||
break;
|
|
||||||
case SIGABRT:
|
|
||||||
BlueScreen("Unexpected program abort");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
BlueScreen(ByteString(message).FromUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr int SCALE_MAXIMUM = 10;
|
constexpr int SCALE_MAXIMUM = 10;
|
||||||
@@ -176,6 +184,11 @@ int main(int argc, char * argv[])
|
|||||||
{
|
{
|
||||||
Platform::SetupCrt();
|
Platform::SetupCrt();
|
||||||
Platform::Atexit([]() {
|
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();
|
SDLClose();
|
||||||
explicitSingletons.reset();
|
explicitSingletons.reset();
|
||||||
});
|
});
|
||||||
@@ -381,10 +394,10 @@ int main(int argc, char * argv[])
|
|||||||
if (enableBluescreen)
|
if (enableBluescreen)
|
||||||
{
|
{
|
||||||
//Get ready to catch any dodgy errors
|
//Get ready to catch any dodgy errors
|
||||||
signal(SIGSEGV, SigHandler);
|
for (auto *msg = signalMessages; msg->message; ++msg)
|
||||||
signal(SIGFPE, SigHandler);
|
{
|
||||||
signal(SIGILL, SigHandler);
|
signal(msg->sig, SigHandler);
|
||||||
signal(SIGABRT, SigHandler);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if constexpr (X86)
|
if constexpr (X86)
|
||||||
|
Reference in New Issue
Block a user