Skip to content

Aggregated issues related to SDL 2 window creation #246

@macsforme

Description

@macsforme

Here I attempted to summarize all the current information about our problems creating windows with SDL 2. This is mostly other people's work, so please edit or add to the info here if needed.

BZFlag Issues Reported

#201 bzflag is not working properly with 3+ monitors

This is caused by a bug in SDL 2. If you have a primary display with a lower resolution than a secondary display and you launch BZFlag, the game window shows up on the secondary display (we always request the primary display), and SDL throws a resize event with the resolution of the secondary display. In addition to the window going onto the wrong display, this confuses BZFlag due to our window resize event handling. See #238 below for a workaround in progress, and see SDL #4990 for the report on the SDL bug tracker.

#241 Fullscreen toggling on macOS broken

When switching between a maximized window and a native fullscreen window via F1 on macOS, then pressing F1 again to switch back, the window is no longer maximized and the window content is offset by approximately the height of the window title bar. Our logic in SDL2Window::create() where we compare the resolutions before and after may be to blame. It may be worth comparing behaviors between the several methods available in SDL 2 to switch between windowed and fullscreen mode (e.g., SDL_SetWindowFullscreen() vs. SDL_MaximizeWindow()/SDL_RestoreWindow() vs. destroying and recreating the window).

#245 Retina scaling broken on macOS (again) in 10.15 Catalina

Based on a single report from a user that the window content is not properly laid out when using retina display scaling in macOS. We need to try to reproduce and confirm this issue.

#88 Resolution testing race condition

Not strictly related, but if the ultimate solution involves deeper adjustments to our fullscreen resolution picker, this one either might be worth fixing at the same time, or might go away on its own.

SDL Bugs Reported

SDL #4990 SDL2 fullscreen windows on Linux are created on secondary monitor

See our #201 above.

SDL #4177 SDL_MinimizeWindow() fails to minimize fullscreen window on macOS

The SDL 2 team reports that this bug is fixed in their development code. After we verify this on our end, and after the fix makes it into the next SDL 2 release, we should remove our workaround code. Confirmed fixed.

SDL #3146 Improper window resized event generated when toggling fullscreen on Mac OS X

This may have been fixed in SDL 2 already. We should test and verify, then if fixed we should close the bug on their tracker and remove our workaround code. Confirmed fixed; SDL bug closed.

Existing Pull Requests

#228 Do not recreate window every time

Little explanation was provided about these changes or how they were supposed to fix any issues. The issue was then closed without explanation, possibly being abandoned in favor of #238. There may still be useful information in the conversation for reference, including this comment about our a possible issue with our event checking:

... we currently process the SDL_WINDOWEVENT_RESIZED event, but it appears this only applies to user interactions, such as dragging the corner to resize and (possibly?) maximizing via the toolbar. If we want to catch resize events generated by the API, I think we may want to use SDL_WINDOWEVENT_SIZE_CHANGED instead.

#238 SDL2: Only create the window once

This is a workaround in progress for our issue #201 and SDL #4990, where a non-fullscreen window is created first, and then resized to fullscreen if needed. Current shortcomings are the loss of the ability to change fullscreen resolution via the menus (the content appears offset on the screen), and the loss of ability to change from a maximized window to a native fullscreen window via F1 on macOS (a black screen results).

SDL 2 window creation call process

Using a debugger to check the backtrace at every call to SDL2Window::create(), I found it is called at the following locations:

  • At the initial window creation when the program starts at bzflag.cxx:1161 or 1163 (depending on whether the game was launched in fullscreen or windowed mode)
  • In startPlaying() at playing.cxx:7484, when the game window is initially shown
  • Through the resize callbacks during the program start or game start, including:
    • Right after the initial call during the program start at bzflag.cxx:1173 (seems superfluous)
    • In SceneRenderer::setRadarSize() at SceneRenderer.cxx:411
    • In SceneRenderer::setPanelHeight() at SceneRenderer.cxx:420
    • In SceneRenderer::setMaxMotionFactor() at SceneRenderer.cxx:443
    • In startPlaying() at playing.cxx:7537 after verifying the BZDB resolution setting is a valid mode for our display (again, seems superfluous)
  • Through the resize callbacks at other times, including:
    • When F1 is pressed to toggle in or out of fullscreen mode in cmdToggleFS() at clientCommands.cxx:233
    • When a BzfEvent::Resize event is received (due to a window corner drag, or a window maximize/restoration via the toolbar at least on macOS) at playing.cxx:1097
    • When the video format is set through the menus in setVideoFormat() at playing.cxx:479

So from what I can deduce, SDL2Window::create() has several purposes for being called, which all need to be accounted for in its logic. These include:

  • Initial window creation at the start of the game
  • When we need to tell SDL to change the window in or out of fullscreen mode, or to tell SDL to change the window to a different fullscreen resolution mode
  • When we are notified that the window size was already changed due to a window corner drag or by maximizing via the title bar; in this case, there is nothing to do, and we should already have the new size stored internally via a previous call to SDL2Window::setSize() in the BzfEvent::Resize event handler, so we should exit as early as possible

I hope this helps with planning as we try to fix the issues with our current window creation code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions