From d9ca68e6eaecfbdc8c277f899c3af8380d9d14d4 Mon Sep 17 00:00:00 2001 From: Mykhailo Pylyp Date: Tue, 1 Dec 2020 12:03:24 +0200 Subject: [PATCH] Add error handling for all possible failing of winrt::check_result (#8278) --- src/modules/shortcut_guide/shortcut_guide.cpp | 11 ++++++- src/modules/shortcut_guide/target_state.cpp | 30 +++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/modules/shortcut_guide/shortcut_guide.cpp b/src/modules/shortcut_guide/shortcut_guide.cpp index eae7cc7335..478470a8dc 100644 --- a/src/modules/shortcut_guide/shortcut_guide.cpp +++ b/src/modules/shortcut_guide/shortcut_guide.cpp @@ -233,7 +233,16 @@ void OverlayWindow::enable() winkey_popup->apply_overlay_opacity(((float)overlayOpacity.value) / 100.0f); winkey_popup->set_theme(theme.value); target_state = std::make_unique(pressTime.value); - winkey_popup->initialize(); + try + { + winkey_popup->initialize(); + } + catch (...) + { + Logger::critical("Winkey popup failed to initialize"); + return; + } + #if defined(DISABLE_LOWLEVEL_HOOKS_WHEN_DEBUGGED) const bool hook_disabled = IsDebuggerPresent(); #else diff --git a/src/modules/shortcut_guide/target_state.cpp b/src/modules/shortcut_guide/target_state.cpp index bf0f14a125..e8ca601695 100644 --- a/src/modules/shortcut_guide/target_state.cpp +++ b/src/modules/shortcut_guide/target_state.cpp @@ -3,6 +3,7 @@ #include "common/start_visible.h" #include "keyboard_state.h" #include "common/shared_constants.h" +#include TargetState::TargetState(int ms_delay) : // TODO: All this processing should be done w/o a separate thread etc. in pre_wnd_proc of winkey_popup to avoid @@ -143,13 +144,36 @@ void TargetState::thread_proc() handle_hidden(); break; case Timeout: - handle_timeout(); + try + { + handle_timeout(); + } + catch (...) + { + Logger::critical("Timeout, handle_timeout failed."); + } break; case Shown: - handle_shown(false); + try + { + handle_shown(false); + } + catch (...) + { + Logger::critical("Shown, handle_shown failed."); + } + break; case ForceShown: - handle_shown(true); + try + { + handle_shown(true); + } + catch (...) + { + Logger::critical("ForceShown, handle_shown failed."); + } + break; case Exiting: default: