From f72ef286737b5e3a00701fb1c941f6650619aa42 Mon Sep 17 00:00:00 2001 From: nicebyte <12521759+nicebyte@users.noreply.github.com> Date: Wed, 27 Dec 2023 20:31:11 -0800 Subject: [PATCH] [glfw] Early-out of GLFW WndProc hook if ImGui has already been torn down If we happen to call `glfwTerminate` after destroying the ImGui context, the WndProc that ImGui installs still gets triggered, but there is no backend data at that time. This is a simple one-line fix that just early-outs if `bd` is NULL for whatever reason. --- backends/imgui_impl_glfw.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index 60723d2700ef..b88f270f172a 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -483,6 +483,7 @@ static ImGuiMouseSource GetMouseSourceFromMessageExtraInfo() static LRESULT CALLBACK ImGui_ImplGlfw_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); + if (!bd) { return DefWindowProc(hWnd, msg, wParam, lParam); } switch (msg) { case WM_MOUSEMOVE: case WM_NCMOUSEMOVE: