impr: Better recovery from exceptions thrown in main thread (#1577)

This PR improves many things which can be seen by the commit name, but
the most important thing is the addition of a popup telling the user
when an exception is thrown

![image](https://github.com/WerWolv/ImHex/assets/42669835/db796416-9cce-4aa5-ad60-c22f05b5fc73)
This commit is contained in:
WerWolv
2024-03-02 15:57:30 +01:00
parent 8e27eb8d36
commit 4a118b94cc
5 changed files with 74 additions and 10 deletions

View File

@@ -126,6 +126,7 @@ namespace hex {
throw;
} catch (const std::exception &e) {
log::fatal("Unhandled exception: {}", e.what());
EventCrashRecovered::post(e);
} catch (...) {
log::fatal("Unhandled exception: Unknown exception");
}
@@ -133,15 +134,19 @@ namespace hex {
void errorRecoverLogCallback(void*, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
std::string message;
message.resize(std::vsnprintf(nullptr, 0, fmt, args));
std::vsnprintf(message.data(), message.size(), fmt, args);
message.resize(message.size() - 1);
va_start(args, fmt);
message.resize(std::vsnprintf(nullptr, 0, fmt, args));
va_end(args);
va_start(args, fmt);
std::vsnprintf(message.data(), message.size(), fmt, args);
va_end(args);
message.resize(message.size() - 1);
log::error("{}", message);
}