Skip to content

Commit 5b41d2f

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

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
@@ -3377,7 +3377,16 @@ namespace ImGui
33773377
IMGUI_API ImGuiIO& GetIO(ImGuiContext* ctx);
33783378
IMGUI_API ImGuiPlatformIO& GetPlatformIO(ImGuiContext* ctx);
33793379
inline ImGuiWindow* GetCurrentWindowRead() { ImGuiContext& g = *GImGui; return g.CurrentWindow; }
3380-
inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; }
3380+
inline ImGuiWindow* GetCurrentWindow()
3381+
{
3382+
ImGuiContext& g = *GImGui;
3383+
#ifdef IMGUI_BUNDLE_PYTHON_API
3384+
// Help python users, because otherwise, this leads to an un-debuggable segfault
3385+
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().");
3386+
#endif
3387+
g.CurrentWindow->WriteAccessed = true;
3388+
return g.CurrentWindow;
3389+
}
33813390
IMGUI_API ImGuiWindow* FindWindowByID(ImGuiID id);
33823391
IMGUI_API ImGuiWindow* FindWindowByName(const char* name);
33833392
IMGUI_API void UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window);

0 commit comments

Comments
 (0)