From 42781fbacd22546266ce5d29e257cdc2b2661a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 14 Apr 2016 16:51:13 +0200 Subject: [PATCH 1/2] Do not try to unref NULL CoglObjects https://bugzilla.gnome.org/show_bug.cgi?id=765058 --- src/backends/meta-cursor.c | 3 ++- src/compositor/meta-surface-actor-x11.c | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backends/meta-cursor.c b/src/backends/meta-cursor.c index 22a8a76..ad468c0 100644 --- a/src/backends/meta-cursor.c +++ b/src/backends/meta-cursor.c @@ -55,7 +55,8 @@ meta_cursor_reference_ref (MetaCursorReference *self) static void meta_cursor_image_free (MetaCursorImage *image) { - cogl_object_unref (image->texture); + if (image->texture) + cogl_object_unref (image->texture); #ifdef HAVE_NATIVE_BACKEND if (image->bo) diff --git a/src/compositor/meta-surface-actor-x11.c b/src/compositor/meta-surface-actor-x11.c index 4aa7ecd..4a5ac00 100644 --- a/src/compositor/meta-surface-actor-x11.c +++ b/src/compositor/meta-surface-actor-x11.c @@ -102,8 +102,7 @@ detach_pixmap (MetaSurfaceActorX11 *self) priv->pixmap = None; meta_error_trap_pop (display); - cogl_object_unref (priv->texture); - priv->texture = NULL; + g_clear_pointer (&priv->texture, cogl_object_unref); } static void -- 2.7.3 From 9522c6ff9bf311c9590ceb6a54cadc75f27ea6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 14 Apr 2016 15:30:31 +0200 Subject: [PATCH 2/2] Do not skip CoglError parameters While CoglError is a define to GError, it doesn't follow the convention of ignoring errors when NULL is passed, but rather treats the error as fatal :-( That's clearly unwanted for a compositor, so make sure to always pass an error parameter where a runtime error is possible (i.e. any CoglError that is not a malformed blend string). https://bugzilla.gnome.org/show_bug.cgi?id=765058 --- src/backends/meta-cursor-tracker.c | 9 ++++++++- src/backends/meta-cursor.c | 18 ++++++++++++++++-- src/compositor/meta-background-image.c | 4 +++- src/compositor/meta-background.c | 10 +++++++++- src/compositor/meta-shadow-factory.c | 10 +++++++++- src/compositor/meta-surface-actor-x11.c | 10 ++++++++-- src/compositor/meta-window-actor.c | 10 +++++++++- src/wayland/meta-wayland-buffer.c | 8 +++++++- 8 files changed, 69 insertions(+), 10 deletions(-) diff --git a/src/backends/meta-cursor-tracker.c b/src/backends/meta-cursor-tracker.c index a649cb4..e2ce3af 100644 --- a/src/backends/meta-cursor-tracker.c +++ b/src/backends/meta-cursor-tracker.c @@ -213,6 +213,7 @@ ensure_xfixes_cursor (MetaCursorTracker *tracker) guint8 *cursor_data; gboolean free_cursor_data; CoglContext *ctx; + CoglError *error = NULL; if (tracker->xfixes_cursor) return; @@ -254,11 +255,17 @@ ensure_xfixes_cursor (MetaCursorTracker *tracker) CLUTTER_CAIRO_FORMAT_ARGB32, cursor_image->width * 4, /* stride */ cursor_data, - NULL); + &error); if (free_cursor_data) g_free (cursor_data); + if (error != NULL) + { + meta_warning ("Failed to allocate cursor sprite texture: %s\n", error->message); + cogl_error_free (error); + } + if (sprite != NULL) { MetaCursorReference *cursor = meta_cursor_reference_take_texture (sprite, diff --git a/src/backends/meta-cursor.c b/src/backends/meta-cursor.c index ad468c0..e2a7f76 100644 --- a/src/backends/meta-cursor.c +++ b/src/backends/meta-cursor.c @@ -222,6 +222,7 @@ meta_cursor_image_load_from_xcursor_image (MetaCursorImage *image, CoglPixelFormat cogl_format; ClutterBackend *clutter_backend; CoglContext *cogl_context; + CoglError *error = NULL; width = xc_image->width; height = xc_image->height; @@ -243,7 +244,13 @@ meta_cursor_image_load_from_xcursor_image (MetaCursorImage *image, cogl_format, rowstride, (uint8_t *) xc_image->pixels, - NULL); + &error); + + if (error) + { + meta_warning ("Failed to allocate cursor texture: %s\n", error->message); + cogl_error_free (error); + } #ifdef HAVE_NATIVE_BACKEND struct gbm_device *gbm = get_gbm_device (); @@ -284,6 +291,7 @@ meta_cursor_image_load_from_buffer (MetaCursorImage *image, { ClutterBackend *backend; CoglContext *cogl_context; + CoglError *error = NULL; image->hot_x = hot_x; image->hot_y = hot_y; @@ -291,7 +299,13 @@ meta_cursor_image_load_from_buffer (MetaCursorImage *image, backend = clutter_get_default_backend (); cogl_context = clutter_backend_get_cogl_context (backend); - image->texture = cogl_wayland_texture_2d_new_from_buffer (cogl_context, buffer, NULL); + image->texture = cogl_wayland_texture_2d_new_from_buffer (cogl_context, buffer, &error); + + if (error) + { + meta_warning ("Failed to allocate cursor texture:%s\n", error->message); + cogl_error_free (error); + } #ifdef HAVE_NATIVE_BACKEND struct gbm_device *gbm = get_gbm_device (); diff --git a/src/compositor/meta-background-image.c b/src/compositor/meta-background-image.c index af66755..0d36246 100644 --- a/src/compositor/meta-background-image.c +++ b/src/compositor/meta-background-image.c @@ -144,6 +144,7 @@ file_loaded (GObject *source_object, { MetaBackgroundImage *image = META_BACKGROUND_IMAGE (source_object); GError *error = NULL; + CoglError *catch_error = NULL; GTask *task; CoglTexture *texture; GdkPixbuf *pixbuf; @@ -176,9 +177,10 @@ file_loaded (GObject *source_object, has_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888, row_stride, pixels, 0, - NULL)) + &catch_error)) { g_warning ("Failed to create texture for background"); + cogl_error_free (catch_error); cogl_object_unref (texture); } diff --git a/src/compositor/meta-background.c b/src/compositor/meta-background.c index 75fbc28..de0407b 100644 --- a/src/compositor/meta-background.c +++ b/src/compositor/meta-background.c @@ -17,6 +17,7 @@ * along with this program; if not, see . */ +#include #include #include #include "meta-background-private.h" @@ -515,6 +516,7 @@ ensure_color_texture (MetaBackground *self) { ClutterBackend *backend = clutter_get_default_backend (); CoglContext *ctx = clutter_backend_get_cogl_context (backend); + CoglError *error = NULL; uint8_t pixels[6]; int width, height; @@ -555,7 +557,13 @@ ensure_color_texture (MetaBackground *self) COGL_PIXEL_FORMAT_RGB_888, width * 3, pixels, - NULL)); + &error)); + + if (error != NULL) + { + meta_warning ("Failed to allocate color texture: %s\n", error->message); + cogl_error_free (error); + } } } diff --git a/src/compositor/meta-shadow-factory.c b/src/compositor/meta-shadow-factory.c index 0a60398..b2c5a1e 100644 --- a/src/compositor/meta-shadow-factory.c +++ b/src/compositor/meta-shadow-factory.c @@ -26,6 +26,7 @@ #include #include +#include #include "cogl-utils.h" #include "meta-shadow-factory-private.h" #include "region-utils.h" @@ -706,6 +707,7 @@ make_shadow (MetaShadow *shadow, { ClutterBackend *backend = clutter_get_default_backend (); CoglContext *ctx = clutter_backend_get_cogl_context (backend); + CoglError *error = NULL; int d = get_box_filter_size (shadow->key.radius); int spread = get_shadow_spread (shadow->key.radius); cairo_rectangle_int_t extents; @@ -803,7 +805,13 @@ make_shadow (MetaShadow *shadow, (buffer + (y_offset - shadow->outer_border_top) * buffer_width + (x_offset - shadow->outer_border_left)), - NULL)); + &error)); + + if (error) + { + meta_warning ("Failed to allocate shadow texture: %s\n", error->message); + cogl_error_free (error); + } cairo_region_destroy (row_convolve_region); cairo_region_destroy (column_convolve_region); diff --git a/src/compositor/meta-surface-actor-x11.c b/src/compositor/meta-surface-actor-x11.c index 4a5ac00..62f517b 100644 --- a/src/compositor/meta-surface-actor-x11.c +++ b/src/compositor/meta-surface-actor-x11.c @@ -113,14 +113,20 @@ set_pixmap (MetaSurfaceActorX11 *self, CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ()); MetaShapedTexture *stex = meta_surface_actor_get_texture (META_SURFACE_ACTOR (self)); + CoglError *error = NULL; CoglTexture *texture; g_assert (priv->pixmap == None); priv->pixmap = pixmap; - texture = COGL_TEXTURE (cogl_texture_pixmap_x11_new (ctx, priv->pixmap, FALSE, NULL)); + texture = COGL_TEXTURE (cogl_texture_pixmap_x11_new (ctx, priv->pixmap, FALSE, &error)); - if (G_UNLIKELY (!cogl_texture_pixmap_x11_is_using_tfp_extension (COGL_TEXTURE_PIXMAP_X11 (texture)))) + if (error != NULL) + { + g_warning ("Failed to allocate stex texture: %s", error->message); + cogl_error_free (error); + } + else if (G_UNLIKELY (!cogl_texture_pixmap_x11_is_using_tfp_extension (COGL_TEXTURE_PIXMAP_X11 (texture)))) g_warning ("NOTE: Not using GLX TFP!\n"); priv->texture = texture; diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c index 476abbf..edc21e3 100644 --- a/src/compositor/meta-window-actor.c +++ b/src/compositor/meta-window-actor.c @@ -1791,9 +1791,17 @@ build_and_scan_frame_mask (MetaWindowActor *self, } else { + CoglError *error = NULL; + mask_texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, tex_width, tex_height, COGL_PIXEL_FORMAT_A_8, - stride, mask_data, NULL)); + stride, mask_data, &error)); + + if (error) + { + g_warning ("Failed to allocate mask texture: %s", error->message); + cogl_error_free (error); + } } meta_shaped_texture_set_mask_texture (stex, mask_texture); diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c index 40db3b0..eda2326 100644 --- a/src/wayland/meta-wayland-buffer.c +++ b/src/wayland/meta-wayland-buffer.c @@ -131,7 +131,13 @@ meta_wayland_buffer_process_damage (MetaWaylandBuffer *buffer, cogl_wayland_texture_set_region_from_shm_buffer (buffer->texture, rect.x, rect.y, rect.width, rect.height, shm_buffer, - rect.x, rect.y, 0, NULL); + rect.x, rect.y, 0, &error); + + if (error) + { + meta_warning ("Failed to set texture region: %s\n", error->message); + cogl_error_free (error); + } } } } -- 2.7.3