mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-01 22:30:42 -07:00
signal: show Windows popup window on crash (#410)
## Link to GitHub Issue, if one exists #345 ## Description of change Show a MessageBox when signal detects a crash. ## Testing Tested full screen and windowed games.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "signal.h"
|
#include "signal.h"
|
||||||
|
|
||||||
|
#include <future>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@@ -174,6 +175,18 @@ static LONG WINAPI TopLevelExceptionFilter(struct _EXCEPTION_POINTERS *Exception
|
|||||||
log_warning("signal", "minidump creation function not available, skipping");
|
log_warning("signal", "minidump creation function not available, skipping");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reduce sleep time since we will wait for the user to acknowledge the popup
|
||||||
|
LOG_FATAL_SLEEP = 1;
|
||||||
|
|
||||||
|
// in 30 seconds, shut down (in case user can't dismiss popup)
|
||||||
|
const auto f = std::async(std::launch::async, [] {
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(30));
|
||||||
|
log_fatal("signal", "end");
|
||||||
|
});
|
||||||
|
|
||||||
|
// this will stall all UI threads for this process
|
||||||
|
deferredlogs::show_popup_for_crash();
|
||||||
|
|
||||||
log_fatal("signal", "end");
|
log_fatal("signal", "end");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,4 +72,25 @@ namespace deferredlogs {
|
|||||||
log_warning("troubleshooter", "{}", msg);
|
log_warning("troubleshooter", "{}", msg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void show_popup_for_crash() {
|
||||||
|
static std::once_flag shown;
|
||||||
|
std::call_once(shown, []() {
|
||||||
|
const std::string title = "spice2x (" + to_string(VERSION_STRING_CFG) + ") - crash handler";
|
||||||
|
std::string text;
|
||||||
|
text += "Game has crashed.\n\n";
|
||||||
|
text += "Check log.txt and look for error messages near the end of file.\n\n";
|
||||||
|
text += "Unsure what to do next?\n";
|
||||||
|
text += " * update spice2x to the latest version\n";
|
||||||
|
text += " * check the FAQ on spice2x wiki on github\n";
|
||||||
|
text += " * do NOT screenshot this, instead, share log.txt with someone and ask for help\n\n";
|
||||||
|
text += "Press Enter, Esc, Alt+F4, or click OK to exit. Otherwise, game will close in 30 seconds.";
|
||||||
|
|
||||||
|
MessageBox(
|
||||||
|
nullptr,
|
||||||
|
text.c_str(),
|
||||||
|
title.c_str(),
|
||||||
|
MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,5 @@ namespace deferredlogs {
|
|||||||
|
|
||||||
void defer_error_messages(std::initializer_list<std::string> messages);
|
void defer_error_messages(std::initializer_list<std::string> messages);
|
||||||
void dump_to_logger(bool is_crash=false);
|
void dump_to_logger(bool is_crash=false);
|
||||||
|
void show_popup_for_crash();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
|
DWORD LOG_FATAL_SLEEP = 10000;
|
||||||
|
|
||||||
std::string_view log_get_datetime() {
|
std::string_view log_get_datetime() {
|
||||||
return log_get_datetime(time(nullptr));
|
return log_get_datetime(time(nullptr));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ struct fmt::formatter<fmt_hresult> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern DWORD LOG_FATAL_SLEEP;
|
||||||
|
|
||||||
// misc log
|
// misc log
|
||||||
#define LOG_FORMAT(level, module, fmt_str, ...) fmt::format(FMT_COMPILE("{}" fmt_str "\n"), \
|
#define LOG_FORMAT(level, module, fmt_str, ...) fmt::format(FMT_COMPILE("{}" fmt_str "\n"), \
|
||||||
fmt_log { std::time(nullptr), level, module }, ## __VA_ARGS__)
|
fmt_log { std::time(nullptr), level, module }, ## __VA_ARGS__)
|
||||||
@@ -84,7 +86,7 @@ struct fmt::formatter<fmt_hresult> {
|
|||||||
logger::push(LOG_FORMAT("F", module, format_str, ## __VA_ARGS__), logger::Style::RED); \
|
logger::push(LOG_FORMAT("F", module, format_str, ## __VA_ARGS__), logger::Style::RED); \
|
||||||
logger::push(LOG_FORMAT("F", "spice", "encountered a fatal error, you can close the window or press ctrl + c"), logger::Style::RED); \
|
logger::push(LOG_FORMAT("F", "spice", "encountered a fatal error, you can close the window or press ctrl + c"), logger::Style::RED); \
|
||||||
launcher::stop_subsystems(); \
|
launcher::stop_subsystems(); \
|
||||||
Sleep(10000); \
|
Sleep(LOG_FATAL_SLEEP); \
|
||||||
launcher::kill(); \
|
launcher::kill(); \
|
||||||
std::terminate(); \
|
std::terminate(); \
|
||||||
} ((void) 0 )
|
} ((void) 0 )
|
||||||
|
|||||||
Reference in New Issue
Block a user