From 7f041fe5c8268b352ece6a4df5156e50ce4cb648 Mon Sep 17 00:00:00 2001 From: Ruben Gonzalez Date: Thu, 8 Feb 2024 09:04:04 +0100 Subject: [PATCH] gtk4: Fix segfault running `gst-inspect -a` when GTK4 and GTK3 is installed Segmentation fault when getting default value of paintable property from gtk4paintablesink element when libgtk-4.so.1 from libgstgtk4.so and libgtk-3.so.0 from libgstgtk.so are installed: > cannot register existing type 'GdkDisplayManager' Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/490 Part-of: --- video/gtk4/src/sink/imp.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/video/gtk4/src/sink/imp.rs b/video/gtk4/src/sink/imp.rs index 28936d3f..6671951a 100644 --- a/video/gtk4/src/sink/imp.rs +++ b/video/gtk4/src/sink/imp.rs @@ -99,6 +99,14 @@ impl ObjectImpl for PaintableSink { fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { match pspec.name() { "paintable" => { + // Fix segfault when GTK3 and GTK4 are loaded (e.g. `gst-inspect-1.0 -a`) + // checking if GtkBin is registered to know if libgtk3.so is already present + // GtkBin was dropped for GTK4 https://gitlab.gnome.org/GNOME/gtk/-/commit/3c165b3b77 + if glib::types::Type::from_name("GtkBin").is_some() { + gst::error!(CAT, imp: self, "Skipping the creation of paintable to avoid segfault between GTK3 and GTK4"); + return None::<&gdk::Paintable>.to_value(); + } + let mut paintable = self.paintable.lock().unwrap(); if paintable.is_none() { self.create_paintable(&mut paintable);