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

ImGui::InputTextMultiline assertion failed with ImGui::TreeNodeEx #7926

Closed
tim-tim707 opened this issue Aug 27, 2024 · 1 comment
Closed
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@tim-tim707
Copy link

Version/Branch of Dear ImGui:

Version 1.85 WIP

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Windows 10 + gcc

Full config/build information:

No response

Details:

The following code creates the following assertion fail

Assertion failed at imgui_widgets.cpp line 627
IM_ASSERT(mouse_button >= 0 && mouse_button < ImGuiMouseButton_COUNT);

if (ImGui::TreeNodeEx("Shader edition:")) {
    ImGui::InputTextMultiline("", &imgui_state.vertex_shd, ImVec2(480, 320));
    ImGui::TreePop();
}

It is fixed by adding the proper PushID and PopID calls like so:

if (ImGui::TreeNodeEx("Some Text")) {
        ImGui::PushID("blabla");
        ImGui::InputTextMultiline("", &someText, ImVec2(480, 320));
        ImGui::PopID();
        ImGui::TreePop();
    }

I was surprised by it since I'm a beginner in ImGui, maybe there could be an assertion failed before, or a line of documentation / an answer in the QA at http://dearimgui.org/faq about it ? The documentation of PushID in imgui.h hinted me that adding the calls would fix the issue and it indeed worked, but there were no indication that it was related except Q: Why is my widget not reacting when I click on it?

I'm leaving an issue as documentation for others since I didn't find this when looking in the closed issues. You can consider this issue as solved, but I would like if it were added to the QA or the documentation of TreeNodeEx or similar.

Thanks !

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

Fixed with

if (ImGui::TreeNodeEx("Some Text")) {
        ImGui::PushID("blabla");
        ImGui::InputTextMultiline("", &someText, ImVec2(480, 320));
        ImGui::PopID();
        ImGui::TreePop();
    }
@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Sep 3, 2024
@ocornut
Copy link
Owner

ocornut commented Sep 3, 2024

if (ImGui::TreeNodeEx("Shader edition:")) {
    ImGui::InputTextMultiline("")

You have an ID conflict here: both item are using the same identifier since identifiers are appended/stacked together.

This is indeed covered by the giant FAQ blurb about how the ID Stack works. I think if you read that section carefully you would fully understand that using "" as an identifier is rarely the right thing (but sometimes it can be, notably right after a PushID()).

You don't need to use PushID() you can directly specify an identifier for your input, e.g.

if (ImGui::TreeNodeEx("Shader edition:")) {
    ImGui::InputTextMultiline("##blabla")

PS: "Version 1.85 WIP" is very old in dear imgui land, this is beyond the unsupported mark. Please update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack
Projects
None yet
Development

No branches or pull requests

2 participants