Don't show a blue screen when the window is already closing

This commit is contained in:
Tamás Bálint Misius
2023-06-11 16:58:49 +02:00
parent 04455ada1c
commit f805b15ee5

View File

@@ -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)