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
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2

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