From e3fb47cf982618d75d942facc353748d8716524d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Fri, 16 May 2025 16:10:47 +0300 Subject: [PATCH] Fix flaw in BringToFront using the wrong iterator, ignore dead ones --- src/openrct2-ui/WindowManager.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index 1f2ba6354b..1fd1e137c5 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -1321,14 +1321,22 @@ public: for (auto it = g_window_list.rbegin(); it != g_window_list.rend(); it++) { auto& w2 = *it; + if (w2->flags & WF_DEAD) + { + continue; + } if (!(w2->flags & WF_STICK_TO_FRONT)) { - itDestPos = it.base(); + // base() returns the next element in the list, so we need to decrement it. + itDestPos = std::prev(it.base()); break; } } - std::iter_swap(itSourcePos, itDestPos); + if (itSourcePos != itDestPos) + { + std::iter_swap(itSourcePos, itDestPos); + } w.Invalidate(); if (w.windowPos.x + w.width < 20)