From 0d08b36a73ccb8f8dbc702f6e61628b2d48900b5 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 2 Mar 2024 09:52:09 +0100 Subject: [PATCH] impr: Prevent ImHex from getting stuck in an infinite crash loop --- main/gui/source/window/window.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 7ca504fe3..af2eae62d 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -151,14 +151,30 @@ namespace hex { } void Window::fullFrame() { + static u32 crashWatchdog = 0; + try { this->frameBegin(); this->frame(); this->frameEnd(); + + // Feed the watchdog + crashWatchdog = 0; } catch (...) { + // If an exception keeps being thrown, abort the application after 10 frames + // This is done to avoid the application getting stuck in an infinite loop of exceptions + crashWatchdog += 1; + if (crashWatchdog > 10) { + log::fatal("Crash watchdog triggered, aborting"); + std::abort(); + } + + // Try to recover from the exception by bringing ImGui back into a working state ImGui::ErrorCheckEndFrameRecover(errorRecoverLogCallback, nullptr); ImGui::EndFrame(); ImGui::UpdatePlatformWindows(); + + // Handle the exception handleException(); } }