lv2 / suil

Library for loading and wrapping LV2 plugin UIs
ISC License
11 stars 5 forks source link

Trouble showing gtk UIs in Ubuntu 20.04 (Qt 5 host) #16

Closed jcelerier closed 1 year ago

jcelerier commented 2 years ago

Hi, I'm having some issue with the following case:

On Ubuntu 20.04, by default, Qt uses the qgtk3 platform theme which calls gtk_init.

But when I try to show a calf UI:

(ossia-score:12415): GLib-GObject-WARNING **: 16:04:32.067: cannot register existing type 'GdkDisplayManager'

(ossia-score:12415): GLib-CRITICAL **: 16:04:32.067: g_once_init_leave: assertion 'result != 0' failed

(ossia-score:12415): GLib-GObject-CRITICAL **: 16:04:32.067: g_object_new_with_properties: assertion 'G_TYPE_IS_OBJECT (object_type)' failed

(ossia-score:12415): GLib-GObject-WARNING **: 16:04:32.067: invalid (NULL) pointer instance

(ossia-score:12415): GLib-GObject-CRITICAL **: 16:04:32.067: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(ossia-score:12415): GLib-GObject-WARNING **: 16:04:32.067: invalid (NULL) pointer instance

(ossia-score:12415): GLib-GObject-CRITICAL **: 16:04:32.067: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(ossia-score:12415): GLib-GObject-WARNING **: 16:04:32.070: cannot register existing type 'GdkDisplay'

(ossia-score:12415): GLib-CRITICAL **: 16:04:32.070: g_once_init_leave: assertion 'result != 0' failed

(ossia-score:12415): GLib-GObject-CRITICAL **: 16:04:32.070: g_type_register_static: assertion 'parent_type > 0' failed

(ossia-score:12415): GLib-CRITICAL **: 16:04:32.070: g_once_init_leave: assertion 'result != 0' failed

(ossia-score:12415): GLib-GObject-CRITICAL **: 16:04:32.070: g_object_new_with_properties: assertion 'G_TYPE_IS_OBJECT (object_type)' failed
Erreur de segmentation (core dumped)

with the following stack trace:

(gdb) bt
#0  0x00007fff54962aa5 in gdk_display_open () at /lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0
#1  0x00007fff5493116a in gdk_display_open_default_libgtk_only () at /lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0
#2  0x00007fff54b05f4d in gtk_init () at /lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0
#3  0x00007fff6e9087ee in suil_wrapper_new () at /usr/lib/x86_64-linux-gnu/suil-0/libsuil_gtk2_in_qt5.so
#4  0x00007ffff16a405c in suil_instance_new () at /lib/x86_64-linux-gnu/libsuil-0.so.0

what is the correct thing to do in that case ?

drobilla commented 2 years ago

Apologies for the late reply.

I'm not sure. IIRC the expectation here is that a Qt app shouldn't have called gtk_init itself. An idempotent version of gtk_init would be nice, but there doesn't seem to be one.

What host is this happening in, and why does it initialize Gtk itself?

jcelerier commented 2 years ago

No worries !

I'm not sure. IIRC the expectation here is that a Qt app shouldn't have called gtk_init itself.

Qt on e.g. Ubuntus is configured to use the qgtk3 platform plug-in which makes the Qt apps fit with the GTK look and feel of the system (and thus needs to call GTK functions, thus the gtk_init call) - this is outside of the host's control.

$ gdb kate # or any GUI Qt app
(gdb) b gtk_init
Function "gtk_init" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (gtk_init) pending.
(gdb) r
Starting program: /usr/bin/kate 
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fecf587a700 (LWP 5973)]
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'

Thread 1 "kate" hit Breakpoint 1, 0x00007fecf4a88db0 in gtk_init () from /lib/x86_64-linux-gnu/libgtk-3.so.0
(gdb) bt
#0  0x00007fecf4a88db0 in gtk_init () from /lib/x86_64-linux-gnu/libgtk-3.so.0
#1  0x00007fecf500737f in ?? () from /usr/lib/x86_64-linux-gnu/qt5/plugins/platformthemes/libqgtk3.so
#2  0x00007fecf5001783 in ?? () from /usr/lib/x86_64-linux-gnu/qt5/plugins/platformthemes/libqgtk3.so
#3  0x00007fecfaa64868 in QPlatformThemeFactory::create(QString const&, QString const&) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#4  0x00007fecfaa6e200 in QGuiApplicationPrivate::createPlatformIntegration() () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#5  0x00007fecfaa6f708 in QGuiApplicationPrivate::createEventDispatcher() () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#6  0x00007fecfa54af55 in QCoreApplicationPrivate::init() () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#7  0x00007fecfaa71543 in QGuiApplicationPrivate::init() () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#8  0x00007fecfb0ae3bd in QApplicationPrivate::init() () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#9  0x0000557f2914ed17 in ?? ()
#10 0x00007fecf9f0e083 in __libc_start_main (main=0x557f2914ec50, argc=1, argv=0x7ffe703cf768, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffe703cf758) at ../csu/libc-start.c:308
#11 0x0000557f2915259e in _start ()
(gdb) 
drobilla commented 2 years ago

Ah. Fuunn. I vaguely remember trying to find a way to conditionally call gtk_init but coming up dry. I guess, worst case scenario, there must be some kludge that will tell if it's been called.

Anyway, good to know what the source of the issue is. Thanks for the report, I'll try to look into it.

SpacemanPaul commented 2 years ago

I'm seeing potentially the same issue in Ardour 6.9 on Debian bookworm.

See thread here: https://discourse.ardour.org/t/lv2-plugins-causing-gui-freeze-debian-testing/107552/2

drobilla commented 2 years ago

That's not this issue. As described above, this issue is specific to Qt5 hosts embedding Gtk plugin UIs when the user is using a Qt theme that uses a Gtk engine internally.

drobilla commented 1 year ago

I have removed the wrappers which caused this issue: ad39b43

Sorry if this case is important to you, but Gtk plugin UIs will no longer work in Qt hosts at all, or at least not magically via suil. Gtk2 is EOL, has always been discouraged for plugin UIs (for good reasons we can't do anything about), and in practice this doesn't affect much except Calf (which is unmaintained) in Qt hosts.

jcelerier commented 1 year ago

fair enough, thanks !