Flix01 / imgui

Dear ImGui Addons Branch = plain unmodified dear imgui plus some extra addon.
https://github.com/Flix01/imgui/wiki/ImGui-Addons-Branch-Home
MIT License
396 stars 34 forks source link

Don't dock tabs to container. Add missing m_next_parent fixup case. #31

Closed tom-seddon closed 6 years ago

tom-seddon commented 6 years ago

I found a couple of bugs in the docking code. My UI is somewhat dynamic, so I was fiddling around constantly opening and closing new windows and docking them in random places each time... this stuff would occasionally cause crashes, infinite loops in the tab linked list, and overlapping tab buttons and windows.

Firstly, it was possible to dock a window to a container, if the root window was a container, m_next_parent was NULL, and the docking was due to this bit of code in begin:

if (first || (prev_opened != dock.opened)) {
    Dock* root = m_next_parent ? m_next_parent : getRootDock();
    if (root && (&dock != root) && !dock.parent) {
        doDock(dock, root, next_slot);
    }
    m_next_parent = &dock;
}

So doDock now finds a non-container to dock to when m_next_parent is NULL.

Secondly, m_next_parent wasn't being fixed up if the next parent happened to be the window being undocked.

Note that these fixes are cherry-picked from my imguidock branch, which includes some other stuff that my program depends on, so I haven't tested them in isolation :( - however imgui.cpp does build. Sorry about this.

Thanks,

--Tom

Flix01 commented 6 years ago

Merged. Thanks for your feedback :+1:

Note that these fixes are cherry-picked from my imguidock branch, which includes some other stuff that my program depends on, so I haven't tested them in isolation :( - however imgui.cpp does build. Sorry about this.

No problem. If we find some issue, we can always roll back. But it seems you're used and tested imguidock much more than I have, so your reports are very useful. Thank you again :smile: