SDL: Exiting fullscreen on X11 breaks rendering
I’m on Manjaro with NVIDIA nonfree drivers and X11. inxi -Fz shows me:
Device-2: NVIDIA TU116 [GeForce GTX 1660 SUPER] driver: nvidia
v: 515.65.01
Display: x11 server: X.org v: 1.21.1.4 with: Xwayland v: 22.1.3 driver:
X: loaded: modesetting,nvidia unloaded: nouveau gpu: i915,nvidia
resolution: 1: 1920x1080~60Hz 2: 1440x900~60Hz 3: 2560x1440~60Hz
OpenGL: renderer: NVIDIA GeForce GTX 1660 SUPER/PCIe/SSE2 v: 4.6.0 NVIDIA
515.65.01
Switching an SDL window to fullscreen and back (either desktop windowless fullscreen or real fullscreen) causes the rendering context to apparently lose connection with the window. The window can be moved or closed as usual, but the renderer stops working in a way that’s a little difficult to explain–it looks like when you create a window and don’t clear or present it but still move and resize it.

This occurs with either a built-in SDL_Renderer or with a minimal OpenGL context, although I’ve only demonstrated the SDL_Renderer version below because of the boilerplate length of a GL version. I’ve also verified that this issue occurs with equivalent code in LÖVE, which uses SDL and OpenGL as well. I have not tested Vulkan.
I wasn’t able to find another reported issue with these precise symptoms, although I see there are a couple of other issues regarding multi-monitor setups and fullscreen on Linux.
Minimal reproduction:
#include <SDL2/SDL.h>
void main() {
SDL_Init(SDL_INIT_VIDEO);
int should_exit = 0;
int fullscreen = 0;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_OPENGL, &window, &renderer);
while (!should_exit) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
should_exit = 1;
} else if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.scancode == SDL_SCANCODE_F) {
fullscreen = !fullscreen;
SDL_SetWindowFullscreen(
window,
fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0
);
}
}
}
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 21
Bug filed with Gnome: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5878
If they come back and say “do this instead and that won’t happen,” I’ll reopen this bug to make changes in SDL itself.
Quick followup: this was fixed in Gnome’s revision control a few weeks ago, so expect distros to eventually ship this fix.
https://gitlab.gnome.org/GNOME/mutter/-/commit/46fc94b67f3c1255f5c6be1a33ff8f80d90a0958
Trying to make a small reproduction case for a Gnome bug report…
This is the simplest X11 program I could write to bypass the compositor and toggle fullscreen. Each keypress toggles to/from fullscreen (after six presses it quits).
This does NOT trigger the bug for me, but this is also way simpler than what SDL does.
Confirmed here on Ubuntu 22.04, gnome on x11. I’ll bisect in the morning.