From 40e6289321d5c8c8eb5e6450aafcc7ec697ae170 Mon Sep 17 00:00:00 2001 From: Kaz Wolfe Date: Tue, 12 Apr 2022 18:07:22 -0700 Subject: [PATCH] fix: allow window list edits at any time Slightly tweak the logic of the WindowSystem Draw() to make a shallow copy of the window list before iterating over it. This allows for the list to be edited at any time, but has a trade-off that modifications to the list won't take effect until the next frame, which is negligible and would have been the case anyways. This change does not break any existing APIs, and should incur minimal (if any) performance penalty. --- Dalamud/Interface/Windowing/WindowSystem.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dalamud/Interface/Windowing/WindowSystem.cs b/Dalamud/Interface/Windowing/WindowSystem.cs index 0e3e2d5eb..b43194b22 100644 --- a/Dalamud/Interface/Windowing/WindowSystem.cs +++ b/Dalamud/Interface/Windowing/WindowSystem.cs @@ -106,7 +106,8 @@ namespace Dalamud.Interface.Windowing if (hasNamespace) ImGui.PushID(this.Namespace); - foreach (var window in this.windows) + // Shallow clone the list of windows so that we can edit it without modifying it while the loop is iterating + foreach (var window in this.windows.ToArray()) { #if DEBUG // Log.Verbose($"[WS{(hasNamespace ? "/" + this.Namespace : string.Empty)}] Drawing {window.WindowName}");