From cd606696a6e0503b376c6621dce5748314b594c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 21 May 2024 17:49:33 +0300 Subject: [PATCH] gtk: Fail initialization of the sink if GTK4 is already initialized in the same process Initializing GTK3 and GTK4 in the same process does not work and is not supported. Part-of: --- subprojects/gst-plugins-good/ext/gtk/gstgtkbasesink.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/subprojects/gst-plugins-good/ext/gtk/gstgtkbasesink.c b/subprojects/gst-plugins-good/ext/gtk/gstgtkbasesink.c index 3526171cd4..4eaf6ee723 100644 --- a/subprojects/gst-plugins-good/ext/gtk/gstgtkbasesink.c +++ b/subprojects/gst-plugins-good/ext/gtk/gstgtkbasesink.c @@ -203,6 +203,16 @@ gst_gtk_base_sink_get_widget (GstGtkBaseSink * gtk_sink) if (gtk_sink->widget != NULL) return g_object_ref (gtk_sink->widget); + /* Fix segfault when GTK3 and GTK4 are loaded (e.g. `gst-inspect-1.0 -a`) + * into the same process. + * + * GtkNoMediaFile only exists in GTK4 and is registered as part of + * gtk_init(). */ + if (g_type_from_name ("GtkNoMediaFile")) { + GST_INFO_OBJECT (gtk_sink, "GTK4 is already initialized"); + return NULL; + } + /* Ensure GTK is initialized, this has no side effect if it was already * initialized. Also, we do that lazily, so the application can be first */ if (!gtk_init_check (NULL, NULL)) {