[mutter] cogl/context: Report error if allocating fallback texture failed



commit 9bd2c5c6f2688b3634662eb1e412b6ed9634d4a5
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Tue Sep 7 17:23:40 2021 +0200

    cogl/context: Report error if allocating fallback texture failed
    
    Error out if we fail to allocate the 1x1 all white fallback texture. If
    we don't do this, and instead continue, any future (likely) allocation
    failure will end up in obscure places that assumes the fallback texture
    exists.
    
    Related: https://bugzilla.redhat.com/show_bug.cgi?id=1989726
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1994>

 cogl/cogl/cogl-context.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
---
diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c
index 89019e908d..7ff9f050bb 100644
--- a/cogl/cogl/cogl-context.c
+++ b/cogl/cogl/cogl-context.c
@@ -49,6 +49,7 @@
 #include "cogl-gtype-private.h"
 #include "winsys/cogl-winsys-private.h"
 
+#include <gio/gio.h>
 #include <string.h>
 #include <stdlib.h>
 
@@ -98,6 +99,7 @@ cogl_context_new (CoglDisplay *display,
   uint8_t white_pixel[] = { 0xff, 0xff, 0xff, 0xff };
   const CoglWinsysVtable *winsys;
   int i;
+  GError *local_error = NULL;
 
   _cogl_init ();
 
@@ -188,6 +190,8 @@ cogl_context_new (CoglDisplay *display,
     {
       cogl_object_unref (display);
       g_free (context);
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "Failed to initialize context");
       return NULL;
     }
 
@@ -298,7 +302,15 @@ cogl_context_new (CoglDisplay *display,
                                    COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                                    0, /* rowstride */
                                    white_pixel,
-                                   NULL); /* abort on error */
+                                   &local_error);
+  if (!context->default_gl_texture_2d_tex)
+    {
+      cogl_object_unref (display);
+      g_free (context);
+      g_propagate_prefixed_error (error, local_error,
+                                  "Failed to create 1x1 fallback texture: ");
+      return NULL;
+    }
 
   context->atlases = NULL;
   g_hook_list_init (&context->atlas_reorganize_callbacks, sizeof (GHook));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]