gnome: fix crash in video settings

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

Refs #72531

Change-Id: I82e4468f9130831e1e372094c646561a09e0e703
diff --git a/src/video/video_widget.cpp b/src/video/video_widget.cpp
index f8fc821..ac0080d 100644
--- a/src/video/video_widget.cpp
+++ b/src/video/video_widget.cpp
@@ -415,9 +415,42 @@
         /* 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;
     }