From a8767ec4d8f518e340c3630e7571d9bf75295c76 Mon Sep 17 00:00:00 2001 From: Garrett Leach <66348375+garrettleach@users.noreply.github.com> Date: Fri, 1 Aug 2025 10:03:30 -0500 Subject: [PATCH] Only add full initialized windows to the window list (#24859) This removes the possibility of a race condition where a window is added to the window list but OnOpen has not been called. Many windows use OnOpen to set up required members so if say OnDraw is called it may use uninitialized members. For an example see ProgressWindow. --- src/openrct2-ui/WindowManager.cpp | 35 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index f2f4656224..0f01bcb7fa 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -895,34 +895,33 @@ public: } } - auto itNew = g_window_list.insert(itDestPos, std::move(wp)); - auto w = itNew->get(); - // Setup window - w->classification = cls; - w->flags = flags; + wp->classification = cls; + wp->flags = flags; // Play sounds and flash the window if (!(flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))) { - w->flags |= WF_WHITE_BORDER_MASK; + wp->flags |= WF_WHITE_BORDER_MASK; OpenRCT2::Audio::Play(OpenRCT2::Audio::SoundId::WindowOpen, 0, pos.x + (windowSize.width / 2)); } - w->windowPos = pos; - w->width = windowSize.width; - w->height = windowSize.height; - w->min_width = windowSize.width; - w->max_width = windowSize.width; - w->min_height = windowSize.height; - w->max_height = windowSize.height; + wp->windowPos = pos; + wp->width = windowSize.width; + wp->height = windowSize.height; + wp->min_width = windowSize.width; + wp->max_width = windowSize.width; + wp->min_height = windowSize.height; + wp->max_height = windowSize.height; - w->focus = std::nullopt; + wp->focus = std::nullopt; - ColourSchemeUpdate(w); - w->Invalidate(); - w->OnOpen(); - return w; + ColourSchemeUpdate(wp.get()); + wp->Invalidate(); + wp->OnOpen(); + + auto itNew = g_window_list.insert(itDestPos, std::move(wp)); + return itNew->get(); } /**