Skip to content

Commit d1da769

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

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
@@ -3379,7 +3379,16 @@ namespace ImGui
33793379
// - ImGui::NewFrame() has never been called, which is illegal.
33803380
// - You are calling ImGui functions after ImGui::EndFrame()/ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal.
33813381
inline ImGuiWindow* GetCurrentWindowRead() { ImGuiContext& g = *GImGui; return g.CurrentWindow; }
3382-
inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; }
3382+
inline ImGuiWindow* GetCurrentWindow()
3383+
{
3384+
ImGuiContext& g = *GImGui;
3385+
#ifdef IMGUI_BUNDLE_PYTHON_API
3386+
// Help python users, because otherwise, this leads to an un-debuggable segfault
3387+
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().");
3388+
#endif
3389+
g.CurrentWindow->WriteAccessed = true;
3390+
return g.CurrentWindow;
3391+
}
33833392
IMGUI_API ImGuiWindow* FindWindowByID(ImGuiID id);
33843393
IMGUI_API ImGuiWindow* FindWindowByName(const char* name);
33853394
IMGUI_API void UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window);

0 commit comments

Comments
 (0)