Skip to content

Commit

Permalink
Fix IWindow.Resized being invoked with invalid data during `WindowM…
Browse files Browse the repository at this point in the history
…ode` switch
  • Loading branch information
Susko3 committed Jul 1, 2023
1 parent 2b4f248 commit ab30bfa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion osu.Framework/Platform/SDL2Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions osu.Framework/Platform/SDL2Window_Windowing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,9 @@ private void updateAndFetchWindowSpecifics()
windowState = pendingWindowState.Value;
pendingWindowState = null;

updatingWindowStateAndSize = true;
UpdateWindowStateAndSize(windowState, currentDisplay, currentDisplayMode.Value);
updatingWindowStateAndSize = false;

fetchWindowSize();

Expand Down Expand Up @@ -722,6 +724,15 @@ private void storeWindowPositionToConfig()
/// </summary>
private bool storingSizeToConfig;

/// <summary>
/// Set when <see cref="UpdateWindowStateAndSize"/> is in progress to avoid <see cref="fetchWindowSize"/> being called with invalid data.
/// </summary>
/// <remarks>
/// Since <see cref="UpdateWindowStateAndSize"/> is a multi-step process, intermediary windows size changes might be invalid.
/// This is usually not a problem, but since <see cref="HandleEventFromFilter"/> runs out-of-band, invalid data might appear in those events.
/// </remarks>
private bool updatingWindowStateAndSize;

private void storeWindowSizeToConfig()
{
if (WindowState != WindowState.Normal)
Expand Down

0 comments on commit ab30bfa

Please sign in to comment.