From 2e0cbd72854cf2343c5bcd36d9c5e44da88a433c Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 26 Dec 2025 21:33:06 +0100 Subject: [PATCH] impr: Don't show crash popup when sending ^C to command line (cherry picked from commit d6d70ca076e7843dadb8a5e31d734bd2fea565b8) --- main/gui/include/crash_handlers.hpp | 5 +++++ main/gui/source/crash_handlers.cpp | 14 +++++++++----- main/gui/source/main.cpp | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/main/gui/include/crash_handlers.hpp b/main/gui/include/crash_handlers.hpp index ea38f6299..52c0990e7 100644 --- a/main/gui/include/crash_handlers.hpp +++ b/main/gui/include/crash_handlers.hpp @@ -1,7 +1,12 @@ #pragma once +#include + namespace hex::crash { + using CrashCallback = void (*) (const std::string&); + + void setCrashCallback(CrashCallback callback); void setupCrashHandlers(); } \ No newline at end of file diff --git a/main/gui/source/crash_handlers.cpp b/main/gui/source/crash_handlers.cpp index 01a5f77dd..316f5c5e3 100644 --- a/main/gui/source/crash_handlers.cpp +++ b/main/gui/source/crash_handlers.cpp @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -46,8 +48,11 @@ namespace hex::crash { // Function that decides what should happen on a crash // (either sending a message or saving a crash file, depending on when the crash occurred) - using CrashCallback = void (*) (const std::string&); - static CrashCallback crashCallback = sendNativeMessage; + static CrashCallback s_crashCallback = sendNativeMessage; + + void setCrashCallback(CrashCallback callback) { + s_crashCallback = std::move(callback); + } static std::fs::path s_crashBackupPath; static void saveCrashFile(const std::string& message) { @@ -74,7 +79,7 @@ namespace hex::crash { static void callCrashHandlers(const std::string &msg) { // Call the crash callback - crashCallback(msg); + s_crashCallback(msg); // Print the stacktrace to the console or log file dbg::printStackTrace(trace::getStackTrace()); @@ -213,7 +218,6 @@ namespace hex::crash { HANDLE_SIGNAL(SIGILL); HANDLE_SIGNAL(SIGABRT); HANDLE_SIGNAL(SIGFPE); - HANDLE_SIGNAL(SIGINT); #if defined (SIGBUS) HANDLE_SIGNAL(SIGBUS); @@ -250,7 +254,7 @@ namespace hex::crash { // Change the crash callback when ImHex has finished startup EventImHexStartupFinished::subscribe([]{ - crashCallback = saveCrashFile; + setCrashCallback(saveCrashFile); }); } diff --git a/main/gui/source/main.cpp b/main/gui/source/main.cpp index a7137323a..bd6319372 100644 --- a/main/gui/source/main.cpp +++ b/main/gui/source/main.cpp @@ -53,6 +53,7 @@ int main(int argc, char **argv) { // Handle command line arguments if any have been passed if (argc > 1) { + crash::setCrashCallback([](auto){}); init::runCommandLine(argc, argv); }