From 693967637266ff48fd247821acd0c6cdf66eda6d Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 2 Jan 2023 17:54:50 +0100 Subject: [PATCH] Docking: fixed DockBuilderCopyDockSpace() crashing when windows not in the remapping list are docked on the left or top side of a split. (#6035) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index f66e16e87..7b25d4e13 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -146,6 +146,8 @@ Other changes: Docking+Viewports Branch: +- Docking: Internals: fixed DockBuilderCopyDockSpace() crashing when windows not in the + remapping list are docked on the left or top side of a split. (#6035) - Backends: OSX: fixed typo in ImGui_ImplOSX_GetWindowSize that would cause issues when resiing from OS decorations, if they are enabled on secondary viewports. (#6009) [@sivu] diff --git a/imgui.cpp b/imgui.cpp index 1279fbe7b..5b44042da 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -17740,8 +17740,11 @@ void ImGui::DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_docks } } - // Anything else in the source nodes of 'node_remap_pairs' are windows that were docked in src_dockspace_id but are not owned by it (unaffiliated windows, e.g. "ImGui Demo") + // Anything else in the source nodes of 'node_remap_pairs' are windows that are not included in the remapping list. // Find those windows and move to them to the cloned dock node. This may be optional? + // Dock those are a second step as undocking would invalidate source dock nodes. + struct DockRemainingWindowTask { ImGuiWindow* Window; ImGuiID DockId; DockRemainingWindowTask(ImGuiWindow* window, ImGuiID dock_id) { Window = window; DockId = dock_id; } }; + ImVector dock_remaining_windows; for (int dock_remap_n = 0; dock_remap_n < node_remap_pairs.Size; dock_remap_n += 2) if (ImGuiID src_dock_id = node_remap_pairs[dock_remap_n]) { @@ -17755,9 +17758,11 @@ void ImGui::DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_docks // Docked windows gets redocked into the new node hierarchy. IMGUI_DEBUG_LOG_DOCKING("[docking] Remap window '%s' %08X -> %08X\n", window->Name, src_dock_id, dst_dock_id); - DockBuilderDockWindow(window->Name, dst_dock_id); + dock_remaining_windows.push_back(DockRemainingWindowTask(window, dst_dock_id)); } } + for (const DockRemainingWindowTask& task : dock_remaining_windows) + DockBuilderDockWindow(task.Window->Name, task.DockId); } // FIXME-DOCK: This is awkward because in series of split user is likely to loose access to its root node.