From ab30bfae535237598e561ec348ca8f5a88a4a9f2 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Sat, 1 Jul 2023 15:53:13 +0200 Subject: [PATCH] Fix `IWindow.Resized` being invoked with invalid data during `WindowMode` switch --- osu.Framework/Platform/SDL2Window.cs | 2 +- osu.Framework/Platform/SDL2Window_Windowing.cs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/osu.Framework/Platform/SDL2Window.cs b/osu.Framework/Platform/SDL2Window.cs index 2d8ca20688..28f9efa453 100644 --- a/osu.Framework/Platform/SDL2Window.cs +++ b/osu.Framework/Platform/SDL2Window.cs @@ -326,7 +326,7 @@ protected virtual void HandleEventFromFilter(SDL.SDL_Event evt) case SDL.SDL_EventType.SDL_WINDOWEVENT: // polling via SDL_PollEvent blocks on resizes (https://stackoverflow.com/a/50858339) - if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED) + if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED && !updatingWindowStateAndSize) fetchWindowSize(); break; diff --git a/osu.Framework/Platform/SDL2Window_Windowing.cs b/osu.Framework/Platform/SDL2Window_Windowing.cs index debf407df1..2d63dde10a 100644 --- a/osu.Framework/Platform/SDL2Window_Windowing.cs +++ b/osu.Framework/Platform/SDL2Window_Windowing.cs @@ -534,7 +534,9 @@ private void updateAndFetchWindowSpecifics() windowState = pendingWindowState.Value; pendingWindowState = null; + updatingWindowStateAndSize = true; UpdateWindowStateAndSize(windowState, currentDisplay, currentDisplayMode.Value); + updatingWindowStateAndSize = false; fetchWindowSize(); @@ -722,6 +724,15 @@ private void storeWindowPositionToConfig() /// private bool storingSizeToConfig; + /// + /// Set when is in progress to avoid being called with invalid data. + /// + /// + /// Since is a multi-step process, intermediary windows size changes might be invalid. + /// This is usually not a problem, but since runs out-of-band, invalid data might appear in those events. + /// + private bool updatingWindowStateAndSize; + private void storeWindowSizeToConfig() { if (WindowState != WindowState.Normal)