Skip to content

SDLWindow: MSAA fallback retry + null-safe CreateWindow#2059

Open
AxGord wants to merge 1 commit into
openfl:developfrom
soccertutor:bugfix/sdlwindow-msaa-fallback
Open

SDLWindow: MSAA fallback retry + null-safe CreateWindow#2059
AxGord wants to merge 1 commit into
openfl:developfrom
soccertutor:bugfix/sdlwindow-msaa-fallback

Conversation

@AxGord
Copy link
Copy Markdown

@AxGord AxGord commented May 11, 2026

Summary

Three small defensive fixes in SDLWindow.cpp that we've been carrying
in our production fork (https://github.com/soccertutor/lime) for ~1 year+
on native OpenFL apps shipping to macOS, Windows, Android, and iPad:

  1. MSAA fallback on window creation failure. When flags include
    WINDOW_FLAG_HW_AA / WINDOW_FLAG_HW_AA_HIRES and the initial
    SDL_CreateWindow fails, retry once with multisample buffers
    disabled. The Android Studio emulator (AVD) rejects window requests
    with multisampling, even though it supports the OpenGL context
    itself. Today the only signal a user gets is the generic
    "Could not create SDL window" message and a hard crash — the same
    app launches fine on physical Android hardware with MSAA support.
    The fallback turns "no window at all" into "a window without
    antialiasing."

  2. int width, height;int width = 0, height = 0; in
    GetWidth() / GetHeight(). If SDL_GetWindowSize returns
    without writing one of the values (early-out on a torn-down
    window), the previous version returned a stack-uninitialized int.
    Defensive only — observable as occasional one-frame size jumps
    during shutdown.

  3. Null-safe CreateWindow. If the SDLWindow constructor
    finishes but sdlWindow == NULL (creation failed and we already
    logged), delete the half-constructed wrapper and return NULL
    instead of handing back an object that holds a null SDL handle.
    Without this, every subsequent caller has to defensively null-check
    sdlWindow on its own — and many don't, which manifests as a
    NULL deref deep inside event dispatch on the next frame.

Diff

project/src/backend/sdl/SDLWindow.cpp | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)

Test

The MSAA fallback path is the one with the most observable behaviour
change. Tested in production on an Android AVD that previously refused
to launch any Lime app with <window antialiasing=\"4\"/> in
project.xml — with this patch the app launches successfully with
antialiasing dropped to 0 on the same emulator image. No regression
on physical Android hardware that supports MSAA (the second
SDL_CreateWindow is only attempted when the first failed and MSAA
was requested).

The width/height defensive init has no observable behaviour change in
the happy path, only narrows the window during teardown races.

The null-safe CreateWindow is dead code on platforms where SDL
window creation never half-succeeds, but on the AVD failure path
described above the original code returned a window object pointing
to NULL — every SDL_* call against it then segfaulted. With this
patch the call site sees a clean NULL and can fall back to
Application::onException / display an error.

Risk

  • Hardware/driver combos that previously failed window creation with
    MSAA flags now succeed with MSAA off. Apps that depend on receiving
    an MSAA-enabled context (e.g. expecting glIsEnabled(GL_MULTISAMPLE)
    to be true) and treat its absence as a fatal error would see
    different behaviour. We've never seen that in practice — apps that
    want MSAA enable it via <window antialiasing=\"N\"/> and treat
    "didn't get it" the same as "got it without".
  • No platform code or public API touched outside SDLWindow.cpp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant