Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IM_ASSERT(0 && "Code uses SetCursorPos()/SetCursorScreenPos() to extend window/parent boundaries...") #5911

Closed
BrutPitt opened this issue Nov 22, 2022 · 3 comments
Labels

Comments

@BrutPitt
Copy link

BrutPitt commented Nov 22, 2022

Version/Branch of Dear ImGui:

Version: 1.89 release

Back-end/Renderer/Compiler/OS

Back-ends: GLFW + OpenGL (with GLAD loader)
Compiler: CLang 15.4 - gcc 12.2.1 - VS2019
Operating System: Linux (X11) & Windows 11

My Issue/Question:

I get IM_ASSERT("Code uses SetCursorPos()/SetCursorScreenPos() to extend window/parent boundaries."), in ErrorCheckUsingSetCursorPosToExtendParentBoundaries() function, without an apparent motivation (I believe).

I premise that I have read #5548

This problem seems to occur opening (initially closed) Billboard ImGui::TreeNodeEx (which contains some other ImGui::TreeNodeEx), and only when the CursorPos is outside of "visible" context.
In the following example the trouble happens is in the Colors ImGui::TreeNodeEx (with ColorMap), inside Billboard:

trouble

This is the code where it happens: I removed any unnecessary part to simplify debug

    {
        ImGui::PushStyleColor(ImGuiCol_Text, titleCol);
        const bool isOpen = ImGui::TreeNodeEx(buildID(base, idA++, id),ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_NoTreePushOnOpen,ICON_FA_TINT " Colors");
        ImGui::PopStyleColor();
        if(isOpen) {
            ImGuiStyle& style = ImGui::GetStyle();
            const float buttY = style.FramePadding.y*2+(fontSize * io.FontGlobalScale);

            ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f);
            ImGui::BeginChild(buildID(base, idA++, id), ImVec2(0,ImGui::GetFrameHeightWithSpacing()*7-ImGui::GetStyle().ItemSpacing.y*2), true);

                // other my code here: removed to simplify debug 

                
                //I tried also this:
                //ImGui::SetCursorScreenPos(ImGui::GetCursorScreenPos() + ImVec2(INDENT(border), 0));                
                //ImGui::Dummy(ImVec2(0,0));

                ImGui::SetCursorPosX(4 /*INDENT(border)*/); ImGui::TextDisabled("Hue");
                ImGui::SameLine(INDENT(posB3));       ImGui::TextDisabled("Saturation"); 
                ImGui::SameLine(INDENT(posC3));       ImGui::TextDisabled("Lightness");

            ImGui::EndChild();
            ImGui::PopStyleVar();
        }
    }

If it can be of interest...
For debugging I bypassed/commented IM_ASSERT...

    if (window->DC.CursorPos.x <= window->DC.CursorMaxPos.x && window->DC.CursorPos.y <= window->DC.CursorMaxPos.y)
        return;
    //IM_ASSERT(0 && "Code uses SetCursorPos()/SetCursorScreenPos() to extend window/parent boundaries. Please submit an item e.g. Dummy() to validate extent.");

... and i noticed this values in window->DC:

first
First time (where it would be blocked in IM_ASSERT)

next
Next pass

(both acquired from call ImGui::EndChild(), in previous code)

If you need more tests, i'll be glad to do them.

Adding...
Apart from the "assertion" in Debug mode, I found no apparent problem or malfunction in Release mode.

Thank you in advance.

@ocornut ocornut added the layout label Nov 23, 2022
@ocornut
Copy link
Owner

ocornut commented Nov 23, 2022

This means the last action in a window is moving cursor position beyond contents boundaries and not submitting an item.
The assert seems correct and describes that.

I don't see such pattern in the code you pasted, and cannot repro with the code you pasted. Are you 100% sure that this exact code you pasted triggers the issue in EndChild() ?

Can you try making a minimal standalone repro that I can paste in main.cpp or imgui_demo.cpp ?

ocornut added a commit that referenced this issue Nov 23, 2022
…ates cursor position inside a collapsed/culled window and IMGUI_DISABLE_OBSOLETE_FUNCTIONS is enabled. (#5548, #5911)
@ocornut
Copy link
Owner

ocornut commented Nov 23, 2022

My bad, I understand I was not setting IMGUI_DISABLE_OBSOLETE_FUNCTIONS and this only happen with it.

The condition are:

  • IMGUI_DISABLE_OBSOLETE_FUNCTIONS enabled.
  • Child is entirely clipped and therefore ->SkipItems == true, elements such as Text() are culled.
  • User code is not checking Begin/BeginChild() return vaue calling SetCursorPos functions.
  • Must happen on the first frame when window doesn't have a content size yet.

The same would happen with a Begin()/End() when Collapsed.

Fix is: ErrorCheckUsingSetCursorPosToExtendParentBoundaries() must check SkipItems.
Pushed the fix now: c3d9f8e
Thanks a lot !

@ocornut ocornut closed this as completed Nov 23, 2022
@BrutPitt
Copy link
Author

Tested: works fine!

Thank you a lot to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants