From c6f25432fd61b9f2a50a50625cdc645b4792ebcb Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 16 Jun 2023 23:16:02 +0200 Subject: [PATCH] Undo ImGui shutdown patch, and add missing/reorder shutdown calls The shutdown patch from commit '48c2401c' created another bug where all inputs get collated, and once drawn, emitted to the ImGui interfaces. The patch has been undone, and the 'ImGui_ImplDX11_Shutdown()' call has been placed before 'ImGui_ImplWin32_Shutdown()', as this was how it was performed according to the official documentation and examples provided by Dear ImGui. The call 'ImGui::DestroyContext()' has also been added (taken from the examples). Removed redundant static global bool. --- r5dev/windows/id3dx.cpp | 51 ++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/r5dev/windows/id3dx.cpp b/r5dev/windows/id3dx.cpp index 9465ae47..0e5815df 100644 --- a/r5dev/windows/id3dx.cpp +++ b/r5dev/windows/id3dx.cpp @@ -31,8 +31,7 @@ typedef BOOL(WINAPI* IPostMessageA)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM l typedef BOOL(WINAPI* IPostMessageW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); /////////////////////////////////////////////////////////////////////////////////// -static BOOL s_bInitialized = false; -static BOOL s_bImGuiInitialized = false; +static BOOL s_bInitialized = FALSE; /////////////////////////////////////////////////////////////////////////////////// static IPostMessageA s_oPostMessageA = NULL; @@ -91,38 +90,32 @@ void SetupImGui() ImGuiIO& io = ImGui::GetIO(); io.ImeWindowHandle = *g_pGameWindow; io.ConfigFlags |= ImGuiConfigFlags_IsSRGB; - - s_bImGuiInitialized = true; } void DrawImGui() { - // Only render if the ImGui panels are visible. - if (g_pBrowser->IsVisible() || g_pConsole->IsVisible()) - { - ImGui_ImplDX11_NewFrame(); - ImGui_ImplWin32_NewFrame(); + ImGui_ImplDX11_NewFrame(); + ImGui_ImplWin32_NewFrame(); - ImGui::NewFrame(); + ImGui::NewFrame(); - // This is required to disable the ctrl+tab menu as some users use this shortcut for other things in-game. - // See https://github.com/ocornut/imgui/issues/5641 for more details. - if (GImGui->ConfigNavWindowingKeyNext) - ImGui::SetShortcutRouting(GImGui->ConfigNavWindowingKeyNext, ImGuiKeyOwner_None); - if (GImGui->ConfigNavWindowingKeyPrev) - ImGui::SetShortcutRouting(GImGui->ConfigNavWindowingKeyPrev, ImGuiKeyOwner_None); - - g_pBrowser->RunFrame(); - g_pConsole->RunFrame(); - - ImGui::EndFrame(); - ImGui::Render(); - - ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); - } + // This is required to disable the ctrl+tab menu as some users use this shortcut for other things in-game. + // See https://github.com/ocornut/imgui/issues/5641 for more details. + if (GImGui->ConfigNavWindowingKeyNext) + ImGui::SetShortcutRouting(GImGui->ConfigNavWindowingKeyNext, ImGuiKeyOwner_None); + if (GImGui->ConfigNavWindowingKeyPrev) + ImGui::SetShortcutRouting(GImGui->ConfigNavWindowingKeyPrev, ImGuiKeyOwner_None); g_pBrowser->RunTask(); + g_pBrowser->RunFrame(); + g_pConsole->RunTask(); + g_pConsole->RunFrame(); + + ImGui::EndFrame(); + ImGui::Render(); + + ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); } //################################################################################# @@ -385,13 +378,13 @@ void DirectX_Shutdown() /////////////////////////////////////////////////////////////////////////////// // Shutdown ImGui - if (s_bImGuiInitialized) + if (s_bInitialized) { - ImGui_ImplWin32_Shutdown(); ImGui_ImplDX11_Shutdown(); - s_bImGuiInitialized = false; + ImGui_ImplWin32_Shutdown(); + ImGui::DestroyContext(); + s_bInitialized = false; } - s_bInitialized = false; } void VDXGI::GetAdr(void) const