impr: Make crash handling from non-main threads more resilient

This commit is contained in:
WerWolv
2025-08-27 23:53:46 +02:00
parent abffb8c138
commit bd9e9a7dcf

View File

@@ -77,7 +77,18 @@ namespace hex::crash {
}
}
extern "C" void triggerSafeShutdown(int signalNumber = 0) {
extern "C" [[noreturn]] void triggerSafeShutdown(int signalNumber = 0) {
if (!TaskManager::isMainThread()) {
log::error("Terminating from non-main thread, scheduling termination on main thread");
TaskManager::doLater([signalNumber] {
triggerSafeShutdown(signalNumber);
});
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
// Trigger an event so that plugins can handle crashes
EventAbnormalTermination::post(signalNumber);
@@ -168,7 +179,10 @@ namespace hex::crash {
// Print the current exception info
try {
std::rethrow_exception(std::current_exception());
if (std::uncaught_exceptions() > 0)
std::rethrow_exception(std::current_exception());
else
log::fatal("std::terminate() called without an active exception");
} catch (std::exception &ex) {
std::string exceptionStr = fmt::format("{}()::what() -> {}", trace::demangle(typeid(ex).name()), ex.what());