Skip to content

Commit f5cdf63

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

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
@@ -3213,7 +3213,16 @@ namespace ImGui
32133213
// - You are calling ImGui functions after ImGui::EndFrame()/ImGui::Render() and before the next ImGui::NewFrame(), which is also illegal.
32143214
IMGUI_API ImGuiIO& GetIOEx(ImGuiContext* ctx);
32153215
inline ImGuiWindow* GetCurrentWindowRead() { ImGuiContext& g = *GImGui; return g.CurrentWindow; }
3216-
inline ImGuiWindow* GetCurrentWindow() { ImGuiContext& g = *GImGui; g.CurrentWindow->WriteAccessed = true; return g.CurrentWindow; }
3216+
inline ImGuiWindow* GetCurrentWindow()
3217+
{
3218+
ImGuiContext& g = *GImGui;
3219+
#ifdef IMGUI_BUNDLE_PYTHON_API
3220+
// Help python users, because otherwise, this leads to an un-debuggable segfault
3221+
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().");
3222+
#endif
3223+
g.CurrentWindow->WriteAccessed = true;
3224+
return g.CurrentWindow;
3225+
}
32173226
IMGUI_API ImGuiWindow* FindWindowByID(ImGuiID id);
32183227
IMGUI_API ImGuiWindow* FindWindowByName(const char* name);
32193228
IMGUI_API void UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window);

0 commit comments

Comments
 (0)