From 9bd2c5c6f2688b3634662eb1e412b6ed9634d4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 7 Sep 2021 17:23:40 +0200 Subject: [PATCH] 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: --- 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 89019e908..7ff9f050b 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 #include #include @@ -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));