Open sebageek opened 1 year ago
IIRC, gobject does not allow (or support) shared libraries to be loaded and unloaded as you like. Your observations about the GType stuff seem to be familiar to me. Pls. try again by removing the calls to dlopen
and dlclose
- I would expect it to work.
Apart form that I must admit, that I have little knowledge about gobject and even less time to look into this. If you come up with a solution / workaround I would thankfully integrate it.
I use libinstpatch through various lv2 plugins that are based on fluidsynth. When I load a plugin, unload it and reload it in a plugin host then the last load hangs indefinitely or segfaults inside
instpatch_init()
. This only happens if the plugins are loaded as dynamic shared objects. I can reproduce this with Fluida.lv2 or FluidGM in reaper, carla or BespokeSynth.So, what's problematic here is the second load of a plugin using libinstpatch. The first one works fine, removal works fine, but adding it (or a different plugin using libinstpatch) again crashes or hangs the plugin host.
To reproduce this in a smaller setup I have written a small programm with a
.so
that callsinstpatch_init()
and theninstpatch_close()
. The program can be found here in a gist: https://gist.github.com/sebageek/8c9aedc123f38347a0307827770e397fHere is the output:
Running this in gdb gives me this backtrace:
So to me it looks like the registration of all the custom GTypes results in this behavior, as when (and this is where my guesswork begins) libinstpatch is mapped to a new address the second time the reregistration of all types somehow causes problems. According to the glib documentation there is no way to unregister resources, so I'm not sure how to solve this.
In this issue of Fluida (ff.) it was discussed that leaving a handle open to libinstpatch would get the OS to not remap libinstpatch to a new memory address, thus keep it working, but this is rather a dirty hack than a proper soltion.
The other option - I think - could be to check if the types are already registered, and if so, use them? I tried my hand at this with this small patch, but it only helps for where the GType helpers are written out and not generated by a macro:
As I have not replaced all the macros (e.g.
_DEFINE_TYPE(IpatchFile, ipatch_file, IPATCH_TYPE_ITEM)
) I'm not even sure if this will work (are there pointers to now invalid memory of registered resources in glib?).I've tested this with libinstpatch-1.0-2 (1.1.6-1) from Debian testing and with compiling libinstpatch from current master. Any idea how to solve this so dynamically loaded plugins using libinstpatch won't crash/hang their plugin host?