glx: Fake an X request to make GLX hack work
authorBenjamin Otte <otte@redhat.com>
Tue, 6 Jun 2023 03:13:39 +0000 (05:13 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 6 Jun 2023 03:20:34 +0000 (05:20 +0200)
Sometimes, GLX can decide to use the previous request serial when faking
XErrors via __glXSendError() (look through the Mesa sources to enjoy).
This can cause the error trap we just installed to not feel responsible
for the error. And that makes GDK decide to immediately abort the
application.
That is not what we or GLX want.

So we use a no-op X Request to bump the request number so that when GLX
does its shenanigans, it uses a serial that our error trap will catch.

Fixes a crash in mutter's CI which apparently manages to drive GLX
without an X server.

gdk/x11/gdkglcontext-glx.c

index 4b0ff395beea1e70c6bc5fb29cebc599bb1a3aff..283052244f40f00b5e107725ad5a4cabcc2251e1 100644 (file)
@@ -658,6 +658,13 @@ gdk_x11_gl_context_glx_realize (GdkGLContext  *context,
 
   gdk_x11_display_error_trap_push (display);
 
+  /* Increase XNextRequest because GLX may fake errors with the last request
+   * and we want the error trap to catch them */
+  XChangeWindowAttributes (GDK_DISPLAY_XDISPLAY (display),
+                           GDK_X11_DISPLAY (display)->leader_window,
+                           0,
+                           (XSetWindowAttributes[1]) { 0, });
+
   if (preferred_api == GDK_GL_API_GL)
     {
       api = gdk_x11_context_create_glx_context (context, GDK_GL_API_GL, legacy);