lgi-devs / lgi

Dynamic Lua binding to GObject libraries using GObject-Introspection
MIT License
440 stars 70 forks source link

Flatpak using Gnome 41 runtime fails with Lgi #274

Closed rolandlo closed 3 years ago

rolandlo commented 3 years ago

The Xournal++ flatpak, see also github repo, has worked fine with Lua lgi using the Gnome 3.38 runtime and lgi commit 0fdcf8c677094d0c109dfb199031fdbc0c9c47ea. We use lgi for some plugins, in particular a plugin to migrate font sizes from Xournal++ version 1.0.x to version 1.1.0. After updating to lgi commit 4071f902b635d3a7078c65162fce347367b1371d and using Gnome 41 runtime, that plugin does not work any longer. Other Lua plugins (that do not use lgi) still work.

The error messages I got (reproduced by another developer) are:

(xournalpp:2): GLib-GObject-CRITICAL **: 20:47:46.199: g_boxed_type_register_static: assertion 'g_type_from_name (name) == 0' failed

(xournalpp:2): GLib-CRITICAL **: 20:47:46.199: g_once_init_leave: assertion 'result != 0' failed

(xournalpp:2): GLib-GObject-CRITICAL **: 20:47:46.199: g_boxed_type_register_static: assertion 'g_type_from_name (name) == 0' failed

(xournalpp:2): GLib-CRITICAL **: 20:47:46.199: g_once_init_leave: assertion 'result != 0' failed

(xournalpp:2): Gtk-ERROR **: 20:47:46.200: GTK 2/3 symbols detected. Using GTK 2/3 and GTK 4 in the same process is not supported

Is there a fix for that problem? For further information see this discussion.

CC @psychon

psychon commented 3 years ago

Is there a fix for that problem?

Well... I never saw that error message before. Which piece of code is loading GTK 3 and which piece is loading GTK 4? Did one of them recently-ish upgrade? I tried to find some Lua code, but "that repo" does not contain the code, just flatpack-things.

A random guess would be: You are doing require("lgi").Gtk. This loads the latest version of Gtk that is available. If I understood your discussion link correctly, previously there was just Gtk 3 available, but now there is Gtk 4. Thus, this now loads Gtk 4. You want require("lgi").require("Gtk", "3.0") instead (no idea if it really is 3.0 that you want nor do I really know the meaning of this string. This is just taken from some code of out of lgi's samples/ that `git grep found.)

psychon commented 3 years ago

Yup, you just load the latest version of Gtk that is available: https://github.com/xournalpp/xournalpp/blob/e25f0b0a731d497659a83803e4e8399ceff98624/plugins/MigrateFontSizes/main.lua#L30

Put differently: Sorry, but you are getting what you ask for and I don't think lgi can do anything about this.

rolandlo commented 3 years ago

@psychon Thanks a lot. Indeed this simple change in the Lua plugin fixes the problem.

psychon commented 3 years ago

Thanks for the feedback. I'm glad my random guess was right.