You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SDL_GPU backend on macOS crash (assert) when going fullscreen #8703
On macOS, using the SDL3_GPU backend, when making the demo app window fullscreen with the standard window fullscreen button, it causes an assert/crash when trying to set scissor extents incorrectly. This appears to be due to the ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale() function getting the wrong scale values. Here is a modified version of the function that appears to fix the issue:
static void ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale(SDL_Window* window, ImVec2* out_size, ImVec2* out_framebuffer_scale)
{
int w, h;
int display_w, display_h;
SDL_GetWindowSize(window, &w, &h);
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)
w = h = 0;
if (out_size != nullptr)
*out_size = ImVec2((float)w, (float)h);
// this version using SDL_GetWindowDisplayScale() seems to get the correct scale values
float scale = SDL_GetWindowDisplayScale(window);
if (out_framebuffer_scale != nullptr)
*out_framebuffer_scale = (scale > 0.0f) ? ImVec2(scale, scale) : ImVec2(1.0f, 1.0f);
}
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
The example demo app: example_sdl3_sdlgpu3/main.cpp
Thank you @jclounge. I will investigate this soon.
Are you on latest master?
Some time ago I tried latest with the new texture update feature (#8465) pushed on June 12, and noticed glitches/flickering on macOS. Do you see them?
Thanks @ocornut, yes I was on the latest master at the time of writing yesterday.
Sorry I've barely started looking at SDL and Dear ImGui, but so far I haven't noticed flickering in particular. I'm on an Intel iMac with Radeon 560X running macOS 15.2, and SDL_GPU is using the Metal driver.
EDIT: Now I've looked slightly more and yes I get glitches when changing font size back and forth with the slider in the demo app, particularly for larger sizes. Glyphs go funny for something like a single frame maybe a couple of times per second while sliding the size, but they never stay glitched after sliding stops.
Can you clarify which are the "correct" and "incorrect" value (output of both calls) on your setup while in fullscreen mode, and while not in fullscreen mode?
EDIT: Now I've looked slightly more and yes I get glitches when changing font size back and forth with the slider in the demo app, particularly for larger sizes. Glyphs go funny for something like a single frame maybe a couple of times per second while sliding the size, but they never stay glitched after sliding stops.
Can you clarify which are the "correct" and "incorrect" value (output of both calls) on your setup while in fullscreen mode, and while not in fullscreen mode?
With a 1X scaled screen resolution, I get a scale value of 1 when not in fullscreen mode which is good, but then it goes to something other than 1 when in fullscreen mode which ends up causing the scissor assert.
e.g. In this line: *out_framebuffer_scale = (w > 0 && h > 0) ? ImVec2((float)display_w / w, (float)display_h / h) : ImVec2(1.0f, 1.0f); I just now got the values: w = 1280, h = 720, display_w = 2048, display_h = 1152, which results in a scale of 1.6 .
Those w and h values appear to be the size of the main app window before it was triggered to go fullscreen, so if the window is first resized before it's fullscreened, the scale ends up different again.
When the above modified function is used instead, the scale stays at 1 in both non-fullscreen and fullscreen, and scissor appears to work: there's no assert and the scrollable content of the demo window is clipped as expected.
With a 2X scaled (retina) screen resolution, the scale value is 2 when not in fullscreen, but then similarly goes different when going to fullscreen. Using the modified function, the scale stays at value 2 in both non-fullscreen and fullscreen modes and scissor seems to work.
Could you try with SDL_GetWindowPixelDensity() instead?
SDL_GetWindowDisplayScale() is definitively incorrect under e.g. Windows as it is a combination of density and user-facing scale, but SDL_GetWindowPixelDensity() may be good.
I just ran an experiment to see what the scale values are doing. First I commented out the scissor commands that have the asserts in them, so the app can keep running when going fullscreen. Then I added this code into the example code to print changes of scale value and how many frames between changes:
...
ImGui::NewFrame();
static ImVec2 curScale;
static int numFramesSameScale = 0;
if (io.DisplayFramebufferScale != curScale)
{
curScale = io.DisplayFramebufferScale;
printf("After %d frames, new scale is now %f\n", numFramesSameScale, curScale.x);
numFramesSameScale = 0;
}
numFramesSameScale ++;
...
The output from starting, to going fullscreen, then going back to non-fullscreen, looks like this:
After 0 frames, new scale is now 1.000000
After 105 frames, new scale is now 1.600000
After 6 frames, new scale is now 1.000000
After 145 frames, new scale is now 0.625000
After 5 frames, new scale is now 1.000000
Program ended with exit code: 0
So it looks like the scale was wrong for 6 frames when going fullscreen, then was correct again, then when leaving fullscreen the scale went wrong again for 5 frames, but again settled to the correct value.
Another run I did had 8 frames of wrong value, so the duration of getting bad values is pretty random.
EDIT: Maybe it's something in SDL itself? I'm using the latest binary release, SDL3-3.2.16 .
Do you get the same results out of ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale() when using the SDL3+OpenGL, SDL3+SDLRenderer, SDL3+Vulkan examples?
Your debug output would be simpler to read if you included the return value of all functions (resolutions etc). You can use IMGUI_DEBUG_LOG() to include a frame counter in the printout.
I think it is worth reporting to SDL3.
We probably can workaround the issue by using your suggested replacement but for Mac only, not on other systems.
Do you get the same results out of ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale() when using the SDL3+OpenGL, SDL3+SDLRenderer, SDL3+Vulkan examples?
Your debug output would be simpler to read if you included the return value of all functions (resolutions etc). You can use IMGUI_DEBUG_LOG() to include a frame counter in the printout.
I think it is worth reporting to SDL3.
We probably can workaround the issue by using your suggested replacement but for Mac only, not on other systems.
Sorry I haven't done all of that yet, but what I have now done is test SDL3+OpenGL3 and the problem doesn't occur there. However, when testing with SDL2+Metal, the problem is there, so it's not just with SDL3 but also SDL2. I'm using the latest SDL2-2.32.8 binary release for that test now, but first it was also failing with my old installed SDL2 from way back in 2017. So the primary common factor seems to be Metal running on my machine, unless I've missed something?
Thanks yeah, some kind of workaround sounds good to me, anything to make it work smoothly. :)
Oh here's something strange, the issue only seems to occur when running from inside Xcode! If I go to the executable and run it from finder, the problem goes away. Not sure if this means the asserts are not being executed or something, or what else could be going on.
Sorry I haven't done all of that yet, but what I have now done is test SDL3+OpenGL3 and the problem doesn't occur there. However, when testing with SDL2+Metal, the problem is there, s
Can you clarify if by "the problem" you mean that you verified that the scaling factor were correct/incorrect, or you only checked for the API Asserting? Because OpenGL likely won't assert the same way, regardless of clipping coordinates being correct or it. It's not really important if you get an assert, what's important is that the FramebufferScale is 1.0f or 2.0f.
Can you clarify if by "the problem" you mean that you verified that the scaling factor were correct/incorrect, or you only checked for the API Asserting? Because OpenGL likely won't assert the same way, regardless of clipping coordinates being correct or it. It's not really important if you get an assert, what's important is that the FramebufferScale is 1.0f or 2.0f.
Okay, I checked the SDL3+OpenGL3 version and as you have pointed out, it indeed gets the incorrect scaling values, but just doesn't run into an assert.
Another test, this time using raylib+rlImGui, and the scale values appear to stay consistently correct.
So SDL3+SDL_GPU, SDL2+Metal, and SDL3+OpenGL3 all report incorrect scale values, but raylib+rlImGui reports correct values.
(Also, when SDL3+SDL_GPU is running directly from the terminal, even though it still has the incorrect scaling values it doesn't get stopped at the assert and just keeps running, unlike when it's running from Xcode where the assert causes a debug break.)
Yes it looks like SDL is reporting those values incorrectly even on its own without Dear ImGui there at all. I just tested some other SDL examples, and SDL_GetWindowPixelDensity() has the same issue when called inside those as well.
Sorry about all the hassle with this, and thanks so much for all your help and patience!
What's interesting is that effectively you are also suggesting that SDL_GetWindowDisplayScale() currently doesn't have this problem, and we could use it on Mac/iOS. (But we cannot use it on other systems)
What's interesting is that effectively you are also suggesting that SDL_GetWindowDisplayScale() currently doesn't have this problem, and we could use it on Mac/iOS. (But we cannot use it on other systems)
I've just double-checked with the SDL-only example, and SDL_GetWindowDisplayScale() is still working consistently there too, at least on my iMac. If you think it can work cleanly on Mac/iOS, that's great!
Hi @ocornut, so just to follow up, is this going to be addressed in Dear ImGui? I see the issue was added and then removed from a milestone and I'm not sure what that means.
I have pushed your suggested change for SDL3: 22a6a83
Could you confirm the fix for you?
I would like to make the equivalent change for SDL2 but I am not sure which function to use since SDL_GetWindowDisplayScale() does not exist. Would you be able to experiment and see how you can obtain a reliable value on SDL2 for the equivalent?
Activity
ocornut commentedon Jun 19, 2025
Thank you @jclounge. I will investigate this soon.
Are you on latest master?
Some time ago I tried latest with the new texture update feature (#8465) pushed on June 12, and noticed glitches/flickering on macOS. Do you see them?
jclounge commentedon Jun 20, 2025
Thanks @ocornut, yes I was on the latest master at the time of writing yesterday.
Sorry I've barely started looking at SDL and Dear ImGui, but so far I haven't noticed flickering in particular. I'm on an Intel iMac with Radeon 560X running macOS 15.2, and SDL_GPU is using the Metal driver.
EDIT: Now I've looked slightly more and yes I get glitches when changing font size back and forth with the slider in the demo app, particularly for larger sizes. Glyphs go funny for something like a single frame maybe a couple of times per second while sliding the size, but they never stay glitched after sliding stops.
ocornut commentedon Jun 25, 2025
FYI I cannot reproduce on my MacBook Air.
Can you clarify which are the "correct" and "incorrect" value (output of both calls) on your setup while in fullscreen mode, and while not in fullscreen mode?
Backends: SDLGPU: fixes call to SDL_MapGPUTransferBuffer(). Fixes art…
ocornut commentedon Jun 25, 2025
Those glitches should now be fixed with dcf1450
jclounge commentedon Jun 25, 2025
With a 1X scaled screen resolution, I get a scale value of 1 when not in fullscreen mode which is good, but then it goes to something other than 1 when in fullscreen mode which ends up causing the scissor assert.
e.g. In this line:
*out_framebuffer_scale = (w > 0 && h > 0) ? ImVec2((float)display_w / w, (float)display_h / h) : ImVec2(1.0f, 1.0f);I just now got the values: w = 1280, h = 720, display_w = 2048, display_h = 1152, which results in a scale of 1.6 .Those w and h values appear to be the size of the main app window before it was triggered to go fullscreen, so if the window is first resized before it's fullscreened, the scale ends up different again.
When the above modified function is used instead, the scale stays at 1 in both non-fullscreen and fullscreen, and scissor appears to work: there's no assert and the scrollable content of the demo window is clipped as expected.
With a 2X scaled (retina) screen resolution, the scale value is 2 when not in fullscreen, but then similarly goes different when going to fullscreen. Using the modified function, the scale stays at value 2 in both non-fullscreen and fullscreen modes and scissor seems to work.
ocornut commentedon Jun 25, 2025
Could you try with
SDL_GetWindowPixelDensity()instead?SDL_GetWindowDisplayScale()is definitively incorrect under e.g. Windows as it is a combination of density and user-facing scale, butSDL_GetWindowPixelDensity()may be good.ocornut commentedon Jun 25, 2025
Actually it seems to do what we already do:
Can you confirm that you are having the issue you reported on (1) latest commit and (2) using the unmodified example_sdl3_sdlgpu3/main.cpp example?
jclounge commentedon Jun 25, 2025
Yes, I just updated to latest master, using the unmodified example code, and I still get the scissor assert.
jclounge commentedon Jun 26, 2025
I just ran an experiment to see what the scale values are doing. First I commented out the scissor commands that have the asserts in them, so the app can keep running when going fullscreen. Then I added this code into the example code to print changes of scale value and how many frames between changes:
The output from starting, to going fullscreen, then going back to non-fullscreen, looks like this:
So it looks like the scale was wrong for 6 frames when going fullscreen, then was correct again, then when leaving fullscreen the scale went wrong again for 5 frames, but again settled to the correct value.
Another run I did had 8 frames of wrong value, so the duration of getting bad values is pretty random.
EDIT: Maybe it's something in SDL itself? I'm using the latest binary release, SDL3-3.2.16 .
ocornut commentedon Jun 26, 2025
Do you get the same results out of ImGui_ImplSDL3_GetWindowSizeAndFramebufferScale() when using the SDL3+OpenGL, SDL3+SDLRenderer, SDL3+Vulkan examples?
Your debug output would be simpler to read if you included the return value of all functions (resolutions etc). You can use IMGUI_DEBUG_LOG() to include a frame counter in the printout.
I think it is worth reporting to SDL3.
We probably can workaround the issue by using your suggested replacement but for Mac only, not on other systems.
jclounge commentedon Jun 26, 2025
Sorry I haven't done all of that yet, but what I have now done is test SDL3+OpenGL3 and the problem doesn't occur there. However, when testing with SDL2+Metal, the problem is there, so it's not just with SDL3 but also SDL2. I'm using the latest SDL2-2.32.8 binary release for that test now, but first it was also failing with my old installed SDL2 from way back in 2017. So the primary common factor seems to be Metal running on my machine, unless I've missed something?
Thanks yeah, some kind of workaround sounds good to me, anything to make it work smoothly. :)
jclounge commentedon Jun 26, 2025
Oh here's something strange, the issue only seems to occur when running from inside Xcode! If I go to the executable and run it from finder, the problem goes away. Not sure if this means the asserts are not being executed or something, or what else could be going on.
ocornut commentedon Jun 26, 2025
Can you clarify if by "the problem" you mean that you verified that the scaling factor were correct/incorrect, or you only checked for the API Asserting? Because OpenGL likely won't assert the same way, regardless of clipping coordinates being correct or it.
It's not really important if you get an assert, what's important is that the FramebufferScale is 1.0f or 2.0f.
jclounge commentedon Jun 26, 2025
Okay, I checked the SDL3+OpenGL3 version and as you have pointed out, it indeed gets the incorrect scaling values, but just doesn't run into an assert.
jclounge commentedon Jun 26, 2025
Another test, this time using raylib+rlImGui, and the scale values appear to stay consistently correct.
So SDL3+SDL_GPU, SDL2+Metal, and SDL3+OpenGL3 all report incorrect scale values, but raylib+rlImGui reports correct values.
(Also, when SDL3+SDL_GPU is running directly from the terminal, even though it still has the incorrect scaling values it doesn't get stopped at the assert and just keeps running, unlike when it's running from Xcode where the assert causes a debug break.)
jclounge commentedon Jun 26, 2025
Yes it looks like SDL is reporting those values incorrectly even on its own without Dear ImGui there at all. I just tested some other SDL examples, and SDL_GetWindowPixelDensity() has the same issue when called inside those as well.
Sorry about all the hassle with this, and thanks so much for all your help and patience!
EDIT: I've reported the issue to SDL here.
ocornut commentedon Jun 26, 2025
What's interesting is that effectively you are also suggesting that
SDL_GetWindowDisplayScale()currently doesn't have this problem, and we could use it on Mac/iOS. (But we cannot use it on other systems)jclounge commentedon Jun 26, 2025
I've just double-checked with the SDL-only example, and SDL_GetWindowDisplayScale() is still working consistently there too, at least on my iMac. If you think it can work cleanly on Mac/iOS, that's great!
jclounge commentedon Jul 2, 2025
Hi @ocornut, so just to follow up, is this going to be addressed in Dear ImGui? I see the issue was added and then removed from a milestone and I'm not sure what that means.
ocornut commentedon Jul 2, 2025
I’ll probably implement the workaround but it seems too risky for 1.92 but probably for 1.92.1.
Bump to 1.92
ocornut commentedon Aug 4, 2025
Also see #4414
Backends: SDL3: use SDL_GetWindowDisplayScale() on Mac to output Disp…
ocornut commentedon Sep 15, 2025
Hello @jclounge ,
Sorry for my late answer.
I have pushed your suggested change for SDL3: 22a6a83
I would like to make the equivalent change for SDL2 but I am not sure which function to use since
SDL_GetWindowDisplayScale()does not exist. Would you be able to experiment and see how you can obtain a reliable value on SDL2 for the equivalent?jclounge commentedon Sep 16, 2025
Thanks @ocornut, it works here!
I've had a little look at making a similar workaround for SDL2, but I don't know how to do it, sorry.