SDLWindow: MSAA fallback retry + null-safe CreateWindow#2059
Open
AxGord wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three small defensive fixes in
SDLWindow.cppthat we've been carryingin our production fork (https://github.com/soccertutor/lime) for ~1 year+
on native OpenFL apps shipping to macOS, Windows, Android, and iPad:
MSAA fallback on window creation failure. When
flagsincludeWINDOW_FLAG_HW_AA/WINDOW_FLAG_HW_AA_HIRESand the initialSDL_CreateWindowfails, retry once with multisample buffersdisabled. 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."
int width, height;→int width = 0, height = 0;inGetWidth()/GetHeight(). IfSDL_GetWindowSizereturnswithout 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.
Null-safe
CreateWindow. If theSDLWindowconstructorfinishes but
sdlWindow == NULL(creation failed and we alreadylogged),
deletethe half-constructed wrapper and return NULLinstead of handing back an object that holds a null SDL handle.
Without this, every subsequent caller has to defensively null-check
sdlWindowon its own — and many don't, which manifests as aNULL deref deep inside event dispatch on the next frame.
Diff
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\"/>inproject.xml— with this patch the app launches successfully withantialiasing dropped to 0 on the same emulator image. No regression
on physical Android hardware that supports MSAA (the second
SDL_CreateWindowis only attempted when the first failed and MSAAwas 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
CreateWindowis dead code on platforms where SDLwindow 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 thispatch the call site sees a clean NULL and can fall back to
Application::onException/ display an error.Risk
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".
SDLWindow.cpp.