Magick.NET icon indicating copy to clipboard operation
Magick.NET copied to clipboard

Crash on linux if the system libglib is loaded before Magic.Net gets called

Open tri-bao opened this issue 1 year ago • 5 comments

Magick.NET version

Magick.NET-Q16-AnyCPU 12.1.0

Environment (Operating system, version and so on)

.netcore 6 on ubuntu 22.04 docker container

Description

(process:1): GLib-GObject-WARNING **: 03:35:20.257: cannot register existing type 'gchar'
**
GLib-GObject:ERROR:../gobject/gvaluetypes.c:455:_g_value_types_init: assertion failed: (type == G_TYPE_CHAR)
Bail out! GLib-GObject:ERROR:../gobject/gvaluetypes.c:455:_g_value_types_init: assertion failed: (type == G_TYPE_CHAR)

The error is similar to the following tickets:

  • https://github.com/dlemstra/Magick.NET/issues/1471
  • https://github.com/dlemstra/Magick.NET/issues/1126

That happens when, within the same process, the system glib is loaded before Magick.NET

Glib is built with -Bsymbolic-functions linker flag https://docs.gtk.org/glib/building.html#extra-configuration-options Should Magick.Net be built with the same flag to avoid this error?

Steps to Reproduce

Program.cs

using ImageMagick;

using var image = new MagickImage();
LD_PRELOAD=/lib/x86_64-linux-gnu/libgobject-2.0.so.0 dotnet Test.dll

This error happens

tri-bao avatar Feb 05 '24 05:02 tri-bao

Thanks for providing more info but that could have been added to that other issue. Can you create a small project with a Dockerfile that can be used to reproduce this so I can test the build changes?

dlemstra avatar Feb 05 '24 07:02 dlemstra

@dlemstra I attached the test project with a Dockerfile in the zip Test.zip

Build: docker build -t test-magicknet:local .

Run: docker run -it --rm test-magicknet:local

tri-bao avatar Feb 06 '24 05:02 tri-bao

Using that option did not prevent this issue. I don't know what should be done to prevent this. The odd part is that my library is build statically and the other library is loaded dynamically. I don't understand how this even can cause issues. It might help if I disable asserts but it looks like that requires an upgrade of the library and that was a lot of work last time I did this.

dlemstra avatar Feb 06 '24 21:02 dlemstra

I don't understand either. This probably gives some hints https://github.com/lovell/sharp-libvips/pull/62

tri-bao avatar Feb 15 '24 15:02 tri-bao

It doesn't give me any hints. You or someone else will need to come up with a solution for this.

dlemstra avatar Feb 15 '24 15:02 dlemstra