hime-ime / hime

HIME Input Method Editor
http://hime-ime.github.io
267 stars 48 forks source link

Applications do not start with "cannot register existing type 'GtkIMContext'" #651

Open SyntevoAlex opened 4 years ago

SyntevoAlex commented 4 years ago

This problem was mentioned in other issues: https://github.com/hime-ime/hime/issues/565 https://github.com/hime-ime/hime/issues/580 https://github.com/hime-ime/hime/issues/584

However, none seem to have arrived at solution, and in general strayed in some other direction, so I decided to post a new issue.

When an effected application is started, it prints errors to console and fails to start UI:

GLib-Object-WARNING **:   15:47:30.680: cannot register existing type 'GtkIMContext'
GLib-CRITICAL **:         15:47:30.680: g_once_init_leave: assertion 'result != 0' failed
GLib-GObject-CRITICAL **: 15:47:30.680: g_type_register_dynamic: assertion 'parent_type > 0' failed
GLib-GObject-CRITICAL **: 15:47:30.680: g_object_new_with_properties: assertion 'G_TYPE_IS_OBJECT (object_type)' failed

I have debugged the problem and found that this is because HIME module for GTK3 is incorrectly linked to GTK2 libraries:

$ readelf -d /usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules/im-hime.so
...
0x0000000000000001 (NEEDED)             Shared library: [libgtk-x11-2.0.so.0]
...

The problem develops as follows:

  1. Affected application calls gtk_im_multicontext_get_type() or gtk_im_context_get_type().
  2. This calls gtk_im_context_get_type_once(), which creates the type and saves "did that" flag in GTK3.
  3. HIME also calls gtk_im_context_get_type() from gtk_im_context_hime_register_type().
  4. This time, it's called from GTK2, because HIME is linked to GTK2 libraries.
  5. GTK2 doesn't yet have "did that" flag and tries to register it again, causing a GLib-Object-WARNING.

When building HIME from sources, the problem is fixed and HIME is linked to GTK3. I understand that the problem is possibly fixed by the following commit: abf244af

xatier commented 4 years ago

Hi @SyntevoAlex , thanks for the bug report. I wonder which version/environment the bug occured?

In abf244a, noticed that I used = instead of +=, which would re-assign GTKINC and LDFLAG. If possible, please consider using the latest source, which I have quite a few fixes here and there.

I'm personally using HIME build from trunk on Archlinux, just FYI.

SyntevoAlex commented 4 years ago

The problem for example occurs on Ubuntu 20.04, which has version 0.9.10+git20170427

Building from sources fails:

win-kbm.c:249:8: error: unknown type name ‘GtkStatusIcon’
249 | extern GtkStatusIcon *tray_icon;

I was able to work around that by only building src/im-client and src/gtk3-im. After that, the problem is no longer reproducible, and readelf -d /usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules/im-hime.so confirms that HIME is now correctly linked against GTK3.

I am myself not a user of HIME, but a developer of a product which fails to start with HIME installed :(

xatier commented 4 years ago

I see. Thanks for providing the detailed info. Unfortunately the ubuntu/debian package maintainer of HIME is not active. Let me see if I can bring someone to help upgrade the package to the latest ver.

SyntevoAlex commented 4 years ago

Thanks!

xatier commented 4 years ago

Hey @medicalwei ... would you please take a look? :pray: I'm not familiar with Ubuntu/Debian ecosystems. :cry:

xatier commented 4 years ago

@SyntevoAlex if all we need is the .deb package, please refer to the CI script:

https://github.com/hime-ime/hime/blob/master/distro/debian/ci/entrypoint.sh

SyntevoAlex commented 4 years ago

Unfortunately for me it's more complicated - as a developer of other product that gets broken by HIME, I'm interested in having fixed HIME for all other users. This basically means updating it in Ubuntu (and other Linux where necessary).

medicalwei commented 4 years ago

I am not actually maintaining hime in Debian.

However, as soon as I got my computer back on Thursday I can try building it. Please keep me posted!

xatier commented 4 years ago

@czchen would you be able to help on Debian side? :pray:

SyntevoAlex commented 4 years ago

@tmssngr FYI

medicalwei commented 4 years ago

Hi,

Do you plan to release a new version using tag or release? Or, where do you put your release tarball?

xatier commented 3 years ago

@medicalwei thanks for taking care of this. I just tagged v.0.9.11.

medicalwei commented 3 years ago

I will handle the package uploading soon.

xatier commented 3 years ago

Thank you!