Skip to content

Commit c3e6acd

Browse files
committed
[Bundle]: GetCurrentWindow / add assert for python: Help python users against un-debuggable segfault
1 parent f46499f commit c3e6acd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

imgui_internal.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3329,7 +3329,16 @@ namespace ImGui
33293329
IMGUI_API ImGuiIO& GetIO(ImGuiContext* ctx);
33303330
IMGUI_API ImGuiPlatformIO& GetPlatformIO(ImGuiContext* ctx);
33313331
inline ImGuiWindow* GetCurrentWindowRead() { ImGuiContext& g = *GImGui; return g.CurrentWindow; }
3332-
inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; }
3332+
inline ImGuiWindow* GetCurrentWindow()
3333+
{
3334+
ImGuiContext& g = *GImGui;
3335+
#ifdef IMGUI_BUNDLE_PYTHON_API
3336+
// Help python users, because otherwise, this leads to an un-debuggable segfault
3337+
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().");
3338+
#endif
3339+
g.CurrentWindow->WriteAccessed = true;
3340+
return g.CurrentWindow;
3341+
}
33333342
IMGUI_API ImGuiWindow* FindWindowByID(ImGuiID id);
33343343
IMGUI_API ImGuiWindow* FindWindowByName(const char* name);
33353344
IMGUI_API void UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window);

0 commit comments

Comments
 (0)