imgui: SDL_GPU backend on macOS crash (assert) when going fullscreen

Version/Branch of Dear ImGui:

master

Back-ends:

SDL3_GPU

Compiler, OS:

macOS

Full config/build information:

n/a

Details:

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

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 20 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I’ll probably implement the workaround but it seems too risky for 1.92 but probably for 1.92.1.

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?

Yes, I just updated to latest master, using the unmodified example code, and I still get the scissor assert.

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?

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.

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.

Those glitches should now be fixed with dcf14505e27f16f6cf1933d4834705ed76302637

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.