-
-
Notifications
You must be signed in to change notification settings - Fork 442
SDLWindow: MSAA fallback retry + null-safe CreateWindow #2059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
6370d46
cbc833f
1da6efe
16a34b6
c668007
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,6 +323,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 ()); | ||
|
|
@@ -797,10 +806,9 @@ namespace lime { | |
|
|
||
| int SDLWindow::GetHeight () { | ||
|
|
||
| int width; | ||
| int height; | ||
| int height = 0; | ||
|
|
||
| SDL_GetWindowSize (sdlWindow, &width, &height); | ||
| SDL_GetWindowSize (sdlWindow, NULL, &height); | ||
|
|
||
| return height; | ||
|
|
||
|
|
@@ -880,10 +888,9 @@ namespace lime { | |
|
|
||
| int SDLWindow::GetWidth () { | ||
|
|
||
| int width; | ||
| int height; | ||
| int width = 0; | ||
|
|
||
| SDL_GetWindowSize (sdlWindow, &width, &height); | ||
| SDL_GetWindowSize (sdlWindow, &width, NULL); | ||
|
|
||
| return width; | ||
|
|
||
|
|
@@ -1439,7 +1446,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 nullptr; | ||
|
|
||
| } | ||
|
|
||
| return window; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to make sure all callers of
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — |
||
|
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,17 +115,20 @@ 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); | ||
| frameRate = resolvedFrameRate; | ||
| return; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems this early return causes
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in c668007 — |
||
| } | ||
|
|
||
| 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.__width = NativeCFFI.lime_window_get_width(handle); | ||
|
|
||
| parent.id = NativeCFFI.lime_window_get_id(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(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can SDL_GetWindowSize actually exit without writing these values? Sdl2 docs don't mention that case: https://wiki.libsdl.org/SDL2/SDL_GetWindowSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can, via
CHECK_WINDOW_MAGIC. In SDL2 (src/video/SDL_video.c)SDL_GetWindowSizestarts withCHECK_WINDOW_MAGIC(window, );, which early-returns before writing*w/*hwhen the video subsystem is uninitialized,windowis NULL, orwindow->magicdoesn't match (a destroyed/stale window — the teardown race this guards). The wiki doesn't mention it but the source confirms it, so the= 0init is defensive against exactly that path; the happy path is unaffected.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to provide the source:
https://github.com/libsdl-org/SDL/blob/f0d1101920864995c0c265128cfd7b96eb959ac5/src/video/SDL_video.c#L2399
https://github.com/libsdl-org/SDL/blob/f0d1101920864995c0c265128cfd7b96eb959ac5/src/video/SDL_video.c#L161
The docs also say:
Which can make the code cleaner and avoid setting the one we don't need to 0.
Also as an aside, it looks like in SDL3 we will be able to check the return value of SDL_GetWindowSize to see if it failed: https://wiki.libsdl.org/SDL3/SDL_GetWindowSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call — adopted in 16a34b6.
GetWidth/GetHeightnow passNULLfor the dimension they don't return and only init the one they do (still= 0so theCHECK_WINDOW_MAGICearly-return path stays defensive). Thanks for the SDL source links and the SDL3 return-value note.