glx: Ignore all errors
authorBenjamin Otte <otte@redhat.com>
Mon, 5 Jun 2023 17:12:29 +0000 (19:12 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 6 Jun 2023 03:20:34 +0000 (05:20 +0200)
In error cases, glXCreateContextAttribsARB() will always return NULL so
it is enough to run the loop until the first non-NULL context is
returned.

And at that point, we can just look at the return value and ignore all
errors.

gdk/x11/gdkglcontext-glx.c

index 89571643ebb74a5ad24fbd32e5f7ced8252fe148..07830897f80902b9717faf8b78bcf9e398fa43fc 100644 (file)
@@ -543,14 +543,14 @@ gdk_x11_context_create_glx_context (GdkGLContext *context,
   if (share != NULL)
     share_glx = GDK_X11_GL_CONTEXT_GLX (share);
 
+  gdk_x11_display_error_trap_push (display);
+
   supported_versions = gdk_gl_versions_get_for_api (api);
   for (j = 0; gdk_gl_version_greater_equal (&supported_versions[j], &version); j++)
     {
       context_attribs [major_idx] = gdk_gl_version_get_major (&supported_versions[j]);
       context_attribs [minor_idx] = gdk_gl_version_get_minor (&supported_versions[j]);
 
-      gdk_x11_display_error_trap_push (display);
-
       /* If we don't have access to GLX_ARB_create_context_profile, then
        * we have to fall back to the old GLX 1.3 API.
        */
@@ -568,19 +568,18 @@ gdk_x11_context_create_glx_context (GdkGLContext *context,
                                           True,
                                           context_attribs);
 
-      if (ctx == NULL)
-        {
-          gdk_x11_display_error_trap_pop_ignored (display);
-        }
-      else if (gdk_x11_display_error_trap_pop (display))
-        {
-          glXDestroyContext (dpy, ctx);
-          ctx = NULL;
-        }
-      else
+      if (ctx != NULL)
         break;
     }
 
+  gdk_x11_display_error_trap_pop_ignored (display);
+
+  if (ctx == NULL)
+    {
+      GDK_DISPLAY_DEBUG (display, OPENGL, "Failed to create a GLX context");
+      return 0;
+    }
+
   GDK_DISPLAY_DEBUG (display, OPENGL,
                      "Realized GLX context[%p], %s, version: %d.%d",
                      context_glx->glx_context,