From 7347f4f4e3615bb634611bd8f2b4505b444501a9 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Mon, 9 Jun 2025 14:13:50 +0100 Subject: [PATCH] Some review stuff --- .../crashcatcher/windows_crashcatcher.cpp | 21 ++++++++----------- .../crashcatcher/windows_crashcatcher.hpp | 1 + .../crashcatcher/windows_crashmonitor.cpp | 10 ++++----- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/components/crashcatcher/windows_crashcatcher.cpp b/components/crashcatcher/windows_crashcatcher.cpp index f17078a4a1..bd5e94a6aa 100644 --- a/components/crashcatcher/windows_crashcatcher.cpp +++ b/components/crashcatcher/windows_crashcatcher.cpp @@ -149,10 +149,15 @@ namespace Crash void CrashCatcher::waitMonitor() { - if (WaitForSingleObject(mSignalAppEvent, CrashCatcherTimeout) != WAIT_OBJECT_0) + if (!waitMonitorNoThrow()) throw std::runtime_error("Waiting for monitor failed"); } + bool CrashCatcher::waitMonitorNoThrow() + { + return WaitForSingleObject(mSignalAppEvent, CrashCatcherTimeout) == WAIT_OBJECT_0; + } + void CrashCatcher::signalMonitor() { SetEvent(mSignalMonitorEvent); @@ -236,16 +241,9 @@ namespace Crash signalMonitor(); - try - { - // give monitor a chance to start dumping - // do this in try/catch as dumping might take longer than the timeout and an exception will be thrown when - // we're resumed - waitMonitor(); - } - catch (std::exception) - { - } + // give monitor a chance to start dumping + // as we're suspended, this might time out even if it's successful, so mMonitorStatus is the source of truth + waitMonitorNoThrow(); shmLock(); CrashSHM::Status monitorStatus = mShm->mMonitorStatus; @@ -253,7 +251,6 @@ namespace Crash if (monitorStatus == CrashSHM::Status::DumpedSuccessfully) { - std::string message = "OpenMW has encountered a fatal error.\nCrash dump saved to '" + Misc::StringUtils::u8StringToString(getCrashDumpPath(*mShm).u8string()) + "'.\nPlease report this to https://gitlab.com/OpenMW/openmw/issues !"; diff --git a/components/crashcatcher/windows_crashcatcher.hpp b/components/crashcatcher/windows_crashcatcher.hpp index bcf1ed688d..5bc78b19fa 100644 --- a/components/crashcatcher/windows_crashcatcher.hpp +++ b/components/crashcatcher/windows_crashcatcher.hpp @@ -66,6 +66,7 @@ namespace Crash const std::filesystem::path& freezeDumpName); void waitMonitor(); + bool waitMonitorNoThrow(); void signalMonitor(); diff --git a/components/crashcatcher/windows_crashmonitor.cpp b/components/crashcatcher/windows_crashmonitor.cpp index de5f64a54c..116a678fef 100644 --- a/components/crashcatcher/windows_crashmonitor.cpp +++ b/components/crashcatcher/windows_crashmonitor.cpp @@ -312,12 +312,10 @@ namespace Crash failedDumping(ss.str()); return; } - else - { - shmLock(); - mShm->mMonitorStatus = CrashSHM::Status::DumpedSuccessfully; - shmUnlock(); - } + + shmLock(); + mShm->mMonitorStatus = CrashSHM::Status::DumpedSuccessfully; + shmUnlock(); } catch (const std::exception& e) {