I’ve tried to to use GHex libraries in a small utility application to visualize binary data (not from a full file, but sections of a file). However, when I tried to use such libraries, the appliation starts logging a bunch of critical gtk logs regarding an assertion fail that look like this:
It then starts working for a bit, but quickly crashes (without any other further log) after interacting repeatedly with the HexWidget.
I’ve tried reading GHex code from the repository in order to figure out if there is some setup function I should run, but I have not found any relevant piece of code. It may also be relevant that I’m using gjs instead of C.
Is there any one who has experience with usage of GHex libraries outside GHex itself? Or is there a piece of code in the GHex repo that I should read more carefully? Or is there any conflict with the gjs language bindings?
P.S.: I use fedora, so I have installed the GHex libraries via the dnf and the relevant packages are ghex-libs and ghex-devel both at version 48.0-1.fc43. Since I’m using system libraries, I’m not using flatpak.
P.S.2: For some reason Gtk.Builder did not recognize HexWidget, so I constructed it manually.
For debugging the critical, you should put a breakpoint on g_return_if_fail_warning and see what the offending code is.
Unfortunately, since I’m using language bindings, I’ve no access to such function.
For the crash, you should, too, at least post the stack trace of where it crashes.
I’m not really sure if I did something wrong, but after typing bt full, the following was printed:
Python Exception <class 'gdb.error'>: could not read '.gnu_debugaltlink' section
could not read '.gnu_debugaltlink' section
The only other information that seems kind of useful is something that was printed before gdb had a chance to run. Should I copy it in full here? I tried uploading but I could not do so.
One crash I got was inside key_press_cb here when trying to access self->document. Another one is in hex_widget_dispose, also when trying to unref self->document.
Clearly, HexWidget fails to ref the document (in fact, I’m not seeing a single g_object_ref call in the whole file!). It should be doing so when the document is being set, i.e. the this line should instead read:
self->document = g_value_dup_object (value);
Could you please pass this info to the GHex maintainer?
I just reported the issue. I’ll link it here so it is accessible from here.
Clearly, HexWidget fails to ref the document (in fact, I’m not seeing a single g_object_ref call in the whole file!). It should be doing so when the document is being set, i.e. this line should instead read:
self->document = g_value_dup_object (value);
After reading your diagnostic, I also verified that the crash no longer happens if the document is referenced from somewhere else in the script. Of course, in this case, gjs complains that the HexDocument was finalized while still owned by gjs probably because when the HexWidget is disposed, it decreases the reference count that gjs had increased to keep it alive.
So the crash can probably be consistently reproduced by typing in the HexWidget 10 seconds after nothing else references its HexDocument.