From ec3b2b8029598e3d9fe6fa8b3ad894bba0f97664 Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Fri, 5 Jul 2024 09:27:02 +0200 Subject: [PATCH] [Bundle]: GetCurrentWindow / add assert for python: Help python users against un-debuggable segfault --- imgui_internal.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/imgui_internal.h b/imgui_internal.h index e4e39820c8bb..961c2551577e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -3225,7 +3225,16 @@ namespace ImGui IMGUI_API ImGuiIO& GetIOEx(ImGuiContext* ctx); IMGUI_API ImGuiPlatformIO& GetPlatformIOEx(ImGuiContext* ctx); inline ImGuiWindow* GetCurrentWindowRead() { ImGuiContext& g = *GImGui; return g.CurrentWindow; } - inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; } + inline ImGuiWindow* GetCurrentWindow() + { + ImGuiContext& g = *GImGui; + #ifdef IMGUI_BUNDLE_PYTHON_API + // Help python users, because otherwise, this leads to an un-debuggable segfault + IM_ASSERT(g.CurrentWindow != NULL && "ImGui::GetCurrentWindow() -> CurrentWindow is NULL. This is likely because you are calling ImGui functions after ImGui::EndFrame()/ImGui::Render() and before the next ImGui::NewFrame()."); + #endif + g.CurrentWindow->WriteAccessed = true; + return g.CurrentWindow; + } IMGUI_API ImGuiWindow* FindWindowByID(ImGuiID id); IMGUI_API ImGuiWindow* FindWindowByName(const char* name); IMGUI_API void UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window);