1
0
mirror of synced 2025-02-17 18:59:21 +01:00

impr: Ensure program exits when set_terminate() lambda is called (#1101)

Draft for now because I am waiting for feedback from Jay
This commit is contained in:
iTrooz 2023-05-25 09:30:25 +02:00 committed by GitHub
parent ee94870e83
commit d671cde6d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -152,6 +152,8 @@ namespace hex {
this->exitGLFW();
}
static std::terminate_handler originalHandler;
void Window::registerEventHandlers() {
// Initialize default theme
EventManager::post<RequestChangeTheme>("Dark");
@ -232,7 +234,7 @@ namespace hex {
#undef HANDLE_SIGNAL
}
std::set_terminate([]{
originalHandler = std::set_terminate([]{
try {
std::rethrow_exception(std::current_exception());
} catch (std::exception &ex) {
@ -243,12 +245,11 @@ namespace hex {
);
}
// save crash.json file
saveCrashFile();
// the handler should eventually release a signal, which will be caught and used to handle the crash
originalHandler();
// send the event. It may affect things (like the project path),
// so we do this after saving the crash file
EventManager::post<EventAbnormalTermination>(0);
log::error("Should not happen: original std::set_terminate handler returned. Terminating manually");
exit(EXIT_FAILURE);
});
}