From b37872c5ef5719d2e068e59f35e608dd3fb21f79 Mon Sep 17 00:00:00 2001
From: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
Date: Tue, 5 May 2015 17:51:30 -0400
Subject: [PATCH] gnome: fix crash in video settings

The crash occurs when changing video settings on
systems with cogl < 1.18.

Refs #72531

(cherry picked from commit 6e7b092f5ab23b406ee7d0adbb85228d0157c74f)
Change-Id: I82e4468f9130831e1e372094c646561a09e0e703
---
 src/video/video_widget.cpp | 39 +++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/src/video/video_widget.cpp b/src/video/video_widget.cpp
index f8fc8216..ac0080d0 100644
--- a/src/video/video_widget.cpp
+++ b/src/video/video_widget.cpp
@@ -415,9 +415,42 @@ clutter_render_image(VideoWidgetRenderer* wg_renderer)
         /* render a black frame set the bool back to false, this is likely done
          * when the renderer is stopped so we ignore whether or not it is running
          */
-        auto image_empty = clutter_image_new();
-        clutter_actor_set_content(actor, image_empty);
-        g_object_unref (image_empty);
+        if (auto image_old = clutter_actor_get_content(actor)) {
+            gfloat width;
+            gfloat height;
+            if (clutter_content_get_preferred_size(image_old, &width, &height)) {
+                /* NOTE: this is a workaround for #72531, a crash which occurs
+                 * in cogl < 1.18. We allocate a black frame of the same size
+                 * as the previous image, instead of simply setting an empty or
+                 * a NULL ClutterImage.
+                 */
+                auto image_empty = clutter_image_new();
+                if (auto empty_data = (guint8 *)g_try_malloc0((gsize)width * height * 4)) {
+                    GError* error = NULL;
+                    clutter_image_set_data(
+                            CLUTTER_IMAGE(image_empty),
+                            empty_data,
+                            COGL_PIXEL_FORMAT_BGRA_8888,
+                            (guint)width,
+                            (guint)height,
+                            (guint)width*4,
+                            &error);
+                    if (error) {
+                        g_warning("error rendering empty image to clutter: %s", error->message);
+                        g_clear_error(&error);
+                        g_object_unref(image_empty);
+                        return;
+                    }
+                    clutter_actor_set_content(actor, image_empty);
+                    g_object_unref(image_empty);
+                    g_free(empty_data);
+                } else {
+                    clutter_actor_set_content(actor, NULL);
+                }
+            } else {
+                clutter_actor_set_content(actor, NULL);
+            }
+        }
         wg_renderer->show_black_frame = false;
         return;
     }
-- 
GitLab