From bfd093d22b1a39af711e302a9c4c0cf95fcb75c9 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 2 Jul 2023 11:28:07 +0200 Subject: [PATCH] Fix rare crash in 'ImGui_ImplWin32_WndProcHandler' Don't run the 'ImGui_ImplWin32_WndProcHandler' if we are shutting down. During rare occasions when closing the game while hovering over the game window, 'ImGui_ImplWin32_WndProcHandler' is getting called while parts or all of the ImGui systems have been shut down, leading to a crash. The fix is to check if the engine is restarting or shutting down before running the ImGui window procedure logic. --- r5dev/engine/sys_mainwind.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/r5dev/engine/sys_mainwind.cpp b/r5dev/engine/sys_mainwind.cpp index 493930ba..bca3375e 100644 --- a/r5dev/engine/sys_mainwind.cpp +++ b/r5dev/engine/sys_mainwind.cpp @@ -8,6 +8,7 @@ #include "windows/id3dx.h" #include "windows/input.h" #include "engine/sys_mainwind.h" +#include "engine/sys_engine.h" #include "gameui/IConsole.h" #include "gameui/IBrowser.h" @@ -30,17 +31,25 @@ int CGame::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (!g_bImGuiInitialized) return v_CGame__WindowProc(hWnd, uMsg, wParam, lParam); + const IEngine::EngineState_t state = g_pEngine->GetState(); + + if (state == IEngine::DLL_CLOSE || + state == IEngine::DLL_RESTART) + return v_CGame__WindowProc(hWnd, uMsg, wParam, lParam); + ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam); if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN) { - if (wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind0 || wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind1) + if (wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind0 || + wParam == g_pImGuiConfig->m_ConsoleConfig.m_nBind1) { g_pConsole->m_bActivate ^= true; ResetInput(); // Disable input to game when console is drawn. } - if (wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind0 || wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind1) + if (wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind0 || + wParam == g_pImGuiConfig->m_BrowserConfig.m_nBind1) { g_pBrowser->m_bActivate ^= true; ResetInput(); // Disable input to game when browser is drawn.