Bug#1023847: libsdl2-2.0-0: SDL2 failed to detect remote X11 connection and attempted to use MIT-SHM extension on it

WHR msl0000023508 at gmail.com
Fri Nov 11 11:08:53 GMT 2022


Package: libsdl2-2.0-0
Version: 2.24.2+dfsg-1
Severity: normal
X-Debbugs-Cc: msl0000023508 at gmail.com

Hello.
When trying to run some simple SDL2-based programs over a remote X11 display
(for example SSH X11 forwarding), this version of SDL2 incorrectly enables
MIT-SHM extension, which isn't possible on a remote X11 display.
Running the following test program over a remote display would producing the
error:

$ cat hello-sdl.c 
#include <SDL.h>
#include <stdio.h>

int main() {
	if(SDL_Init(SDL_INIT_VIDEO) < 0) {
		fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
		return 1;
	}
	SDL_Window *window = SDL_CreateWindow("Hello world", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 240, 240, 0);
	if(!window) {
		fprintf(stderr, "SDL_CreateWindow: %s\n", SDL_GetError());
		return 1;
	}
	SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
	if(!renderer) {
		fprintf(stderr, "SDL_CreateRenderer: %s\n", SDL_GetError());
		return 1;
	}
	SDL_RenderPresent(renderer);
	SDL_Event event;
	while(SDL_WaitEvent(&event)) {
		if(event.type == SDL_QUIT) {
			SDL_Quit();
			return 0;
		}
	}
	fprintf(stderr, "SDL_WaitEvent: %s\n", SDL_GetError());
	return 1;
}
$ gcc -Wall -O1 -I /usr/include/SDL2 hello-sdl.c -o hello-sdl -l SDL2
$ echo $DISPLAY
localhost:11.0
$ ./hello-sdl 
X Error of failed request:  BadShmSeg (invalid shared segment parameter)
  Major opcode of failed request:  130 (MIT-SHM)
  Minor opcode of failed request:  3 (X_ShmPutImage)
  Segment id in failed request:  0x460000b
  Serial number of failed request:  232
  Current serial number in output stream:  233


This issue didn't exist in previous versions of SDL2; I have tested
libsdl2-2.0-0 versions 2.0.5+dfsg1-2+deb9u2 and 2.0.9+dfsg1-1 with SSH X11
forwarding, and they are all working fine.

The root cause I think was code in src/video/x11/SDL_x11framebuffer.c uses
XShmQueryExtension(3) to detect whether this extension is available, however
the remote X11 server would simply report that it is available without aware
that it couldn't be used remotely. I think it would be very helpful if SDL
can also check an environment variable for an explicit disablement of this
extension, such as SDL_VIDEO_X11_NO_SHM=1, in case it failed to detect such
automatically. I will submit a patch for this feature later.\


-- System Information:
Debian Release: bookworm/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
merged-usr: no
Architecture: ppc64
Foreign Architectures: powerpc

Kernel: Linux 4.1.42-rivoreo-powerpc64-largepage (SMP w/4 CPU threads)
Kernel taint flags: TAINT_DIE
Locale: LANG=zh_TW.UTF-8, LC_CTYPE=zh_TW.UTF-8 (charmap=UTF-8), LANGUAGE=zh_TW:zh_CN:zh:en_GB:en
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages libsdl2-2.0-0 depends on:
ii  libasound2          1.2.7.2-1
ii  libc6               2.36-4
ii  libdecor-0-0        0.1.1-1
ii  libdrm2             2.4.114-1
ii  libgbm1             22.2.3-1
ii  libpulse0           16.1+dfsg1-2+b1
ii  libsamplerate0      0.2.2-2
ii  libwayland-client0  1.21.0-1
ii  libwayland-cursor0  1.21.0-1
ii  libwayland-egl1     1.21.0-1
ii  libx11-6            2:1.8.1-2
ii  libxcursor1         1:1.2.1-1
ii  libxext6            2:1.3.4-1+b1
ii  libxfixes3          1:6.0.0-2
ii  libxi6              2:1.8-1+b1
ii  libxkbcommon0       1.4.1-1
ii  libxrandr2          2:1.5.2-2+b1
ii  libxss1             1:1.2.3-1

libsdl2-2.0-0 recommends no packages.

Versions of packages libsdl2-2.0-0 suggests:
pn  xdg-utils  <none>

-- no debconf information



More information about the Pkg-sdl-maintainers mailing list