From 6370d46885215c1a29ba1682572b898fffcade4f Mon Sep 17 00:00:00 2001 From: Alexander Gordeyko Date: Sat, 21 Mar 2026 01:48:12 +0200 Subject: [PATCH 1/4] SDLWindow: MSAA fallback retry + null-safe CreateWindow --- project/src/backend/sdl/SDLWindow.cpp | 28 ++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index 6e6459f54f..1a09b15690 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -160,6 +160,15 @@ namespace lime { } #endif + if (!sdlWindow && (flags & (WINDOW_FLAG_HW_AA | WINDOW_FLAG_HW_AA_HIRES))) { + + // Retry without antialiasing — emulators and some devices don't support MSAA + SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 0); + SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, 0); + sdlWindow = SDL_CreateWindow (title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, sdlWindowFlags); + + } + if (!sdlWindow) { printf ("Could not create SDL window: %s.\n", SDL_GetError ()); @@ -584,8 +593,8 @@ namespace lime { int SDLWindow::GetHeight () { - int width; - int height; + int width = 0; + int height = 0; SDL_GetWindowSize (sdlWindow, &width, &height); @@ -667,8 +676,8 @@ namespace lime { int SDLWindow::GetWidth () { - int width; - int height; + int width = 0; + int height = 0; SDL_GetWindowSize (sdlWindow, &width, &height); @@ -1133,7 +1142,16 @@ namespace lime { Window* CreateWindow (Application* application, int width, int height, int flags, const char* title) { - return new SDLWindow (application, width, height, flags, title); + SDLWindow* window = new SDLWindow (application, width, height, flags, title); + + if (!window->sdlWindow) { + + delete window; + return NULL; + + } + + return window; } From cbc833f7355879489812f364acb9c39fc383b05c Mon Sep 17 00:00:00 2001 From: Alexander Gordeyko Date: Sun, 17 May 2026 13:37:37 +0300 Subject: [PATCH 2/4] SDLWindow: nullptr + ASCII comment; NativeWindow: null-safe create Address review on openfl/lime#2059 (tobil4sk): - SDLWindow.cpp: ASCII hyphen instead of em-dash in MSAA-retry comment; return nullptr instead of NULL from CreateWindow (C++). - NativeWindow.hx: create() bailed only partially on a null window handle; lime_window_get_scale/get_context_type(handle) were called unconditionally and deref a null handle. Replace the partial if (handle != null) guard with an early return after lime_window_create. C++ callers (ExternalInterface) were already null-safe via CFFIPointer/HLCFFIPointer. Co-Authored-By: Claude Opus 4.7 (1M context) --- project/src/backend/sdl/SDLWindow.cpp | 4 ++-- .../_internal/backend/native/NativeWindow.hx | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index 1a09b15690..1db4430a77 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -162,7 +162,7 @@ namespace lime { if (!sdlWindow && (flags & (WINDOW_FLAG_HW_AA | WINDOW_FLAG_HW_AA_HIRES))) { - // Retry without antialiasing — emulators and some devices don't support MSAA + // Retry without antialiasing - emulators and some devices don't support MSAA SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, 0); SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, 0); sdlWindow = SDL_CreateWindow (title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, sdlWindowFlags); @@ -1147,7 +1147,7 @@ namespace lime { if (!window->sdlWindow) { delete window; - return NULL; + return nullptr; } diff --git a/src/lime/_internal/backend/native/NativeWindow.hx b/src/lime/_internal/backend/native/NativeWindow.hx index af36f281ff..ab858e7c94 100644 --- a/src/lime/_internal/backend/native/NativeWindow.hx +++ b/src/lime/_internal/backend/native/NativeWindow.hx @@ -109,16 +109,18 @@ class NativeWindow #if (!macro && lime_cffi) handle = NativeCFFI.lime_window_create(parent.application.__backend.handle, width, height, flags, title); - if (handle != null) + if (handle == null) { - parent.__width = NativeCFFI.lime_window_get_width(handle); - parent.__height = NativeCFFI.lime_window_get_height(handle); - parent.__x = NativeCFFI.lime_window_get_x(handle); - parent.__y = NativeCFFI.lime_window_get_y(handle); - parent.__hidden = (Reflect.hasField(attributes, "hidden") && attributes.hidden); - parent.id = NativeCFFI.lime_window_get_id(handle); + return; } + parent.__width = NativeCFFI.lime_window_get_width(handle); + parent.__height = NativeCFFI.lime_window_get_height(handle); + parent.__x = NativeCFFI.lime_window_get_x(handle); + parent.__y = NativeCFFI.lime_window_get_y(handle); + parent.__hidden = (Reflect.hasField(attributes, "hidden") && attributes.hidden); + parent.id = NativeCFFI.lime_window_get_id(handle); + parent.__scale = NativeCFFI.lime_window_get_scale(handle); var context = new RenderContext(); From 16a34b66a5e2b0fd9ff67f225a1b03491ee82f6f Mon Sep 17 00:00:00 2001 From: Alexander Gordeyko Date: Sun, 17 May 2026 17:53:30 +0300 Subject: [PATCH 3/4] SDLWindow: pass NULL for unused SDL_GetWindowSize out-param Per review: SDL_GetWindowSize accepts NULL for an unwanted w/h, so GetWidth/GetHeight only request the value they return and init just that one to 0 (still defensive against the CHECK_WINDOW_MAGIC early return path). Co-Authored-By: Claude Opus 4.7 (1M context) --- project/src/backend/sdl/SDLWindow.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index 017aaa52f0..ebae078944 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -806,10 +806,9 @@ namespace lime { int SDLWindow::GetHeight () { - int width = 0; int height = 0; - SDL_GetWindowSize (sdlWindow, &width, &height); + SDL_GetWindowSize (sdlWindow, NULL, &height); return height; @@ -890,9 +889,8 @@ namespace lime { int SDLWindow::GetWidth () { int width = 0; - int height = 0; - SDL_GetWindowSize (sdlWindow, &width, &height); + SDL_GetWindowSize (sdlWindow, &width, NULL); return width; From c6680070ba1d6183f9f349bf97ff970480b9e94d Mon Sep 17 00:00:00 2001 From: Alexander Gordeyko Date: Sun, 17 May 2026 17:53:30 +0300 Subject: [PATCH 4/4] NativeWindow: set frameRate before null-handle early return Per review: keep frameRate populated even when window creation fails so getFrameRate()'s field fallback is correct. resolvedFrameRate is already computed and the assignment is a plain field write (no handle deref). Co-Authored-By: Claude Opus 4.7 (1M context) --- src/lime/_internal/backend/native/NativeWindow.hx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lime/_internal/backend/native/NativeWindow.hx b/src/lime/_internal/backend/native/NativeWindow.hx index 38d9f08c94..630149e42a 100644 --- a/src/lime/_internal/backend/native/NativeWindow.hx +++ b/src/lime/_internal/backend/native/NativeWindow.hx @@ -117,6 +117,7 @@ class NativeWindow if (handle == null) { + frameRate = resolvedFrameRate; return; }