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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1457>
This commit is contained in:
Ruben Gonzalez 2024-02-08 09:04:04 +01:00 committed by Sebastian Dröge
parent 883bfb6f94
commit 7f041fe5c8

View file

@ -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);