From 4fa59df9fa20e4e2212070c5b1bc6cc52237093f Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 15 Nov 2025 19:06:27 +0100 Subject: [PATCH] Docking: fixed crash loading certain form of invalid .ini settings, (#9070) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 2a9682e90..2a6c544e6 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -152,6 +152,8 @@ Docking+Viewports Branch: - Docking, Style: fixed per-window ImGuiCol_UnsavedMarker changes not being latched by docked windows. (#8983, #9064) +- Docking: fixed crash loading certain form of invalid .ini settings (e.g. nodes + referring to a missing parent, duplicate nodes id). (#9070) - Examples: - SDL2+DX11, SDL3+DX11, Win32+DX10, Win32+DX11: fixed one resource leak from the use of MakeWindowAssociation() in 1.92.4. (#9010, #4350) [@o-3-o] diff --git a/imgui.cpp b/imgui.cpp index 8f92d7965..f8df7b054 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -17894,7 +17894,7 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx) bool remove = false; remove |= (data->CountWindows == 1 && settings->ParentNodeId == 0 && data->CountChildNodes == 0 && !(settings->Flags & ImGuiDockNodeFlags_CentralNode)); // Floating root node with only 1 window remove |= (data->CountWindows == 0 && settings->ParentNodeId == 0 && data->CountChildNodes == 0); // Leaf nodes with 0 window - remove |= (data_root->CountChildWindows == 0); + remove |= (data_root == NULL || data_root->CountChildWindows == 0); if (remove) { IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextPruneUnusedSettingsNodes: Prune 0x%08X\n", settings->ID); @@ -17907,11 +17907,17 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx) static void ImGui::DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDockNodeSettings* node_settings_array, int node_settings_count) { // Build nodes + ImGuiContext& g = *ctx; IM_UNUSED(g); for (int node_n = 0; node_n < node_settings_count; node_n++) { ImGuiDockNodeSettings* settings = &node_settings_array[node_n]; if (settings->ID == 0) continue; + if (DockContextFindNodeByID(ctx, settings->ID) != NULL) + { + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextBuildNodesFromSettings: skip duplicate node 0x%08X\n", settings->ID); + continue; + } ImGuiDockNode* node = DockContextAddNode(ctx, settings->ID); node->ParentNode = settings->ParentNodeId ? DockContextFindNodeByID(ctx, settings->ParentNodeId) : NULL; node->Pos = ImVec2(settings->Pos.x, settings->Pos.y);