Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetVips Native Linux on Ubuntu 18.04 and Unity - cannot register existing type 'gchar' #90

Closed
jsm174 opened this issue Jul 21, 2020 · 33 comments
Labels
bug Something isn't working

Comments

@jsm174
Copy link

jsm174 commented Jul 21, 2020

Hello.

I'm helping on the Visual Pinball Engine project getting it to run on Mac and Linux. You helped us a few weeks ago and added support for mono, and we were successfully able to get it to work on OSX.

We are currently trying to get this running on Ubuntu 18.04.

If we do a base install of Ubuntu 18.04 and then add Mono 6 (Mono JIT compiler version 6.10.0.104 ) and run our test cases, we can see libvips is working.

NetVips.dll.config:

    <dllmap dll="libvips-42.dll" target="libvips.so.42" os="linux" />
    <dllmap dll="libglib-2.0-0.dll" target="libvips.so.42" os="linux" />
    <dllmap dll="libgobject-2.0-0.dll" target="libvips.so.42" os="linux" />

Launch test cases:

MONO_LOG_LEVEL=debug MONO_LOG_MASK=dll mono ~/.nuget/packages/nunit.consolerunner/3.11.1/tools/nunit3-console.exe VisualPinball.Engine.Test/.bin/Release/net472/VisualPinball.Engine.Test.dll

Console:

2020-07-21 08:41:32.7348|INFO|VisualPinball.Engine.VPT.Table.Table|File successfully saved to ShouldWriteSpinnerData.vpx.
2020-07-21 08:41:32.7991|INFO|VisualPinball.Engine.VPT.Table.Table|File successfully saved to ShouldWriteSurfaceData.vpx.
Mono: DllImport attempting to load: 'libvips.so.42'.
Mono: DllImport loaded library '/home/jsm174/git/VisualPinball.Engine/VisualPinball.Engine.Test/.bin/Release/net472/libvips.so.42'.
Mono: DllImport searching in: 'libvips.so.42' ('/home/jsm174/git/VisualPinball.Engine/VisualPinball.Engine.Test/.bin/Release/net472/libvips.so.42').
Mono: Searching for 'vips_init'.
Mono: Probing 'vips_init'.
Mono: Found as 'vips_init'.
Mono: DllImport searching in: 'libvips.so.42' ('/home/jsm174/git/VisualPinball.Engine/VisualPinball.Engine.Test/.bin/Release/net472/libvips.so.42').
Mono: Searching for 'vips_version'.

In Unity, when libvips tries to load it immediately crashes.

Since Unity doesn't seem to load individual dll maps, we updated its config (just like we did for OSX)

~/Unity/Hub/Editor/2020.1.0b16/Editor/Data/MonoBleedingEdge/etc/mono/config:

<configuration>

         <dllmap dll="libvips-42.dll" target="libvips.so.42" os="linux" />
         <dllmap dll="libglib-2.0-0.dll" target="libvips.so.42" os="linux" />
         <dllmap dll="libgobject-2.0-0.dll" target="libvips.so.42" os="linux" />

Launch Unity:

MONO_LOG_LEVEL=debug MONO_LOG_MASK=dll /home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Unity -projectpath "/home/jsm174/New Unity Project (5)" -hubIPC -cloudEnvironment production

Unity Editor Log:

   2667 Mono: DllImport attempting to load: 'libvips.so.42'.
   2668
   2669 (Unity:25706): GLib-GObject-WARNING **: 08:16:43.870: cannot register existing type 'gchar'
   2670 **
   2671 GLib-GObject:ERROR:../gobject/gvaluetypes.c:454:_g_value_types_init: assertion failed: (type == G_TYPE_CHAR)
   2672 Caught fatal signal - signo:6 code:-6 errno:0 addr:0x3e80000646a
   2673 Obtained 42 stack frames.
   2674 #0  0x007f8fd9f8d8a0 in funlockfile
   2675 #1  0x007f8fd9bc8f47 in gsignal
   2676 #2  0x007f8fd9bca8b1 in abort
   2677 #3  0x007f8fdad9a315 in g_assertion_message
   2678 #4  0x007f8fdad9a37a in g_assertion_message_expr
   2679 #5  0x007f8dbf294b6a in _g_value_types_init
   2680 #6  0x007f8dbea0d383 in _init
   2681 #7  0x007f8fe4d84783 in _dl_rtld_di_serinfo
   2682 #8  0x007f8fe4d8924f in _dl_find_dso_for_object
   2683 #9  0x007f8fd9cf151f in _dl_catch_exception
   2684 #10 0x007f8fe4d8881a in _dl_find_dso_for_object
   2685 #11 0x007f8fde38cf96 in (Unknown)
   2686 #12 0x007f8fd9cf151f in _dl_catch_exception
   2687 #13 0x007f8fd9cf15af in _dl_catch_error
   2688 #14 0x007f8fde38d745 in dlerror
   2689 #15 0x007f8fde38d051 in dlopen
   2690 #16 0x00556de1b4c3aa in LoadPluginExecutable(char const*, bool)
   2691 #17 0x00556de1b4dc72 in FindAndLoadUnityPlugin(char const*, void**, bool)
   2692 #18 0x007f8e9821b0ba in mono_lookup_pinvoke_call
   2693 #19 0x007f8e9822e453 in mono_marshal_string_to_utf16
   2694 #20 0x007f8e980ef4c2 in mono_set_break_policy
   2695 #21 0x007f8e9811a6e4 in mono_set_break_policy
   2696 #22 0x007f8e980f83d6 in mono_set_break_policy
   2697 #23 0x007f8e980d4254 in _init
   2698 #24 0x007f8e980d5ccc in _init
   2699 #25 0x007f8e980d99c2 in mono_print_method_from_ip
   2700 #26 0x007f8e98159542 in mono_print_thread_dump_from_ctx
   2701 #27 0x007f8e98159871 in mono_print_thread_dump_from_ctx
   2702 #28 0x00000041c3d393 in (Unknown)
   2703 #29 0x000000420ad118 in <Module>:.cctor ()
   2704 #30 0x007f8e980daa75 in mono_print_method_from_ip
   2705 #31 0x007f8e98249e3c in mono_perfcounter_foreach
   2706 #32 0x007f8e9824c9d1 in mono_object_get_class
   2707 #33 0x007f8e9824c726 in mono_object_get_class
   2708 #34 0x007f8e980d618e in _init
   2709 #35 0x007f8e980d99c2 in mono_print_method_from_ip
   2710 #36 0x007f8e98159542 in mono_print_thread_dump_from_ctx
   2711 #37 0x007f8e98159871 in mono_print_thread_dump_from_ctx
   2712 #38 0x00000041c3d393 in (Unknown)
   2713 #39 0x000000420acd68 in VisualPinball.Engine.VPT.Texture:GetImage ()
   2714 #40 0x000000420acb04 in VisualPinball.Engine.VPT.Texture:Analyze ()
   2715 #41 0x000000420aca5c in VisualPinball.Engine.VPT.Texture:GetStats ()
   2716 Launching bug reporter
   2717 QObject: Cannot create children for a parent that is in a different thread.
   2718 (Parent is QObject(0x24a82b0), parent's thread is QThread(0x210e340), current thread is Thread(0x248a980)
   2719 [Unity Package Manager (Upm)]
   2720 Parent process [25706] was terminated

I know the dllmap is working, because if I omit the entries:

Mono: DllImport attempting to load: 'libvips-42.dll'.
Mono: DllImport error loading library '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libvips-42.dll': '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libvips-42.dll: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libvips-42.dll.so': '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libvips-42.dll.so: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libvips-42.dll': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libvips-42.dll: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libvips-42.dll.so': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libvips-42.dll.so: cannot open shared object file: No such file or directory'.
Fallback handler could not load library /home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42.dll
Mono: DllImport error loading library 'libvips-42.dll': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42.dll: cannot open shared object file: No such file or directory'.
Fallback handler could not load library /home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42.dll.so
Mono: DllImport error loading library 'libvips-42.dll.so': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42.dll.so: cannot open shared object file: No such file or directory'.
Fallback handler could not load library /home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42.dll
Mono: DllImport error loading library 'libvips-42.dll': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42.dll: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libvips-42': '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libvips-42: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libvips-42.so': '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libvips-42.so: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libvips-42': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libvips-42: cannot open shared object file: No such file or directory'.
Mono: DllImport error loading library '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libvips-42.so': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libvips-42.so: cannot open shared object file: No such file or directory'.
Fallback handler could not load library /home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42
Mono: DllImport error loading library 'libvips-42': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42: cannot open shared object file: No such file or directory'.
Fallback handler could not load library /home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42.so
Mono: DllImport error loading library 'libvips-42.so': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42.so: cannot open shared object file: No such file or directory'.
Fallback handler could not load library /home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42
Mono: DllImport error loading library 'libvips-42': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42: cannot open shared object file: No such file or directory'.
Mono: DllImport unable to load library '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/Editor/Data/Mono/lib/libvips-42: cannot open shared object file: No such file or directory'.

I also know that other native libraries are loading successfully:

    651 Mono: DllImport attempting to load: 'libminiz.so.2.1.0'.
    652 Mono: DllImport loaded library '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libminiz.so.2.1.0'.
    653 Mono: DllImport searching in: 'libminiz.so.2.1.0' ('/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libminiz.so.2.1.0').
    654 Mono: Searching for 'wrapper_tinfl_decompressor_size'.
    655 Mono: Probing 'wrapper_tinfl_decompressor_size'.
    656 Mono: Found as 'wrapper_tinfl_decompressor_size'.
    657 Mono: DllImport searching in: 'libminiz.so.2.1.0' ('/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libminiz.so.2.1.0').
    658 Mono: Searching for 'wrapper_tinfl_decompress'.
    659 Mono: Probing 'wrapper_tinfl_decompress'.
    660 Mono: Found as 'wrapper_tinfl_decompress'.

Is it possible, Unity's has its own libglib and libgobject that are conflicting? The mono config file has these entries:

        <dllmap dll="libglib-2.0" target="libglib-2.0.so.0" os="!windows"/>
        <dllmap dll="libgobject-2.0" target="libgobject-2.0.so.0" os="!windows"/>
@jsm174
Copy link
Author

jsm174 commented Jul 23, 2020

Just to follow up on this, I decided to try to use standard packages for libvips (I believe it installed 8.4.5-1build1)

sudo apt install libvips libvips-dev

/usr/lib/x86_64-linux-gnu:

-rw-r--r-- 1 root root 1944800 Jan 18  2017 libvips.so.42.6.5
lrwxrwxrwx 1 root root      17 Jan 18  2017 libvips.so.42 -> libvips.so.42.6.5
lrwxrwxrwx 1 root root      17 Jan 18  2017 libvips.so -> libvips.so.42.6.5

I then modified Unity's config:

        <dllmap dll="libvips-42.dll" target="libvips.so" os="linux" />
        <dllmap dll="libglib-2.0-0.dll" target="libglib-2.0.so.0" os="linux" />
        <dllmap dll="libgobject-2.0-0.dll" target="libgobject-2.0.so.0" os="linux" />

As you can see, I mapped libglib and libgobject to the entries already in Unity's config:

        <dllmap dll="libglib-2.0" target="libglib-2.0.so.0" os="!windows"/>
        <dllmap dll="libgobject-2.0" target="libgobject-2.0.so.0" os="!windows"/>

This seems to work! - although a few undefined symbols, but no crash.

(This now makes me wonder on a correct packaging strategy for our app).

   2667 Mono: DllImport attempting to load: 'libvips.so'.
   2668 Mono: DllImport error loading library '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libvips.so': '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libvips.so: cannot open shared object file: No such file or directory'.
   2669 Mono: DllImport error loading library '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libvips.so': '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libvips.so: cannot open shared object file: No such file or directory'.
   2670 Mono: DllImport error loading library '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libvips.so': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libvips.so: cannot open shared object file: No such file or directory'.
   2671 Mono: DllImport error loading library '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libvips.so': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libvips.so: cannot open shared object file: No such file or directory'.
   2672 Mono: DllImport loaded library 'libvips.so'.
   2673 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2674 Mono: Searching for 'vips_init'.
   2675 Mono: Probing 'vips_init'.
   2676 Mono: Found as 'vips_init'.
   2677 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2678 Mono: Searching for 'vips_version'.
   2679 Mono: Probing 'vips_version'.
   2680 Mono: Found as 'vips_version'.
   2681 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2682 Mono: Searching for 'vips_foreign_find_load_buffer'.
   2683 Mono: Probing 'vips_foreign_find_load_buffer'.
   2684 Mono: Found as 'vips_foreign_find_load_buffer'.
   2685 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2686 Mono: Searching for 'vips_object_set_from_string'.
   2687 Mono: Probing 'vips_object_set_from_string'.
   2688 Mono: Found as 'vips_object_set_from_string'.
   2689 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2690 Mono: Searching for 'vips_cache_operation_build'.
   2691 Mono: Probing 'vips_cache_operation_build'.
   2692 Mono: Found as 'vips_cache_operation_build'.
   2693 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2694 Mono: Searching for 'vips_object_unref_outputs'.
   2695 Mono: Probing 'vips_object_unref_outputs'.
   2696 Mono: Found as 'vips_object_unref_outputs'.
   2697 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2698 Mono: Searching for 'vips_operation_new'.
   2699 Mono: Probing 'vips_operation_new'.
   2700 Mono: Found as 'vips_operation_new'.
   2701 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2702 Mono: Searching for 'vips_object_get_args'.
   2703 Mono: Probing 'vips_object_get_args'.
   2704 Mono: Could not find 'vips_object_get_args' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_object_get_args'.
   2705 Mono: Probing 'vips_object_get_args'.
   2706 Mono: Could not find 'vips_object_get_args' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_object_get_args'.
   2707 Mono: Probing 'vips_object_get_argsA'.
   2708 Mono: Could not find 'vips_object_get_argsA' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_object_get_argsA'.
   2709 Mono: Probing 'vips_object_get_argsA'.
   2710 Mono: Could not find 'vips_object_get_argsA' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_object_get_argsA'.
   2711 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2712 Mono: Searching for 'vips_argument_map'.
   2713 Mono: Probing 'vips_argument_map'.
   2714 Mono: Found as 'vips_argument_map'.
   2715 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2716 Mono: Searching for 'vips_error_clear'.
   2717 Mono: Probing 'vips_error_clear'.
   2718 Mono: Found as 'vips_error_clear'.
   2719 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2720 Mono: Searching for 'vips_object_get_argument'.
   2721 Mono: Probing 'vips_object_get_argument'.
   2722 Mono: Found as 'vips_object_get_argument'.
   2723 Mono: DllImport attempting to load: 'libgobject-2.0.so.0'.
   2724 Mono: DllImport error loading library '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libgobject-2.0.so.0': '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libgobject-2.0.so.0: cannot open shared object file: No such file or directory'.
   2725 Mono: DllImport error loading library '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libgobject-2.0.so.0.so': '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libgobject-2.0.so.0.so: cannot open shared object file: No such file or directory'.
   2726 Mono: DllImport error loading library '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libgobject-2.0.so.0': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libgobject-2.0.so.0: cannot open shared object file: No such file or directory'.
   2727 Mono: DllImport error loading library '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libgobject-2.0.so.0.so': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libgobject-2.0.so.0.so: cannot open shared object file: No such file or directory'.
   2728 Mono: DllImport loaded library 'libgobject-2.0.so.0'.
   2729 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2730 Mono: Searching for 'g_type_from_name'.
   2731 Mono: Probing 'g_type_from_name'.
   2732 Mono: Found as 'g_type_from_name'.
   2733 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2734 Mono: Searching for 'vips_band_format_get_type'.
   2735 Mono: Probing 'vips_band_format_get_type'.
   2736 Mono: Found as 'vips_band_format_get_type'.
   2737 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2738 Mono: Searching for 'vips_blend_mode_get_type'.
   2739 Mono: Probing 'vips_blend_mode_get_type'.
   2740 Mono: Could not find 'vips_blend_mode_get_type' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_blend_mode_get_type'.
   2741 Mono: Probing 'vips_blend_mode_get_type'.
   2742 Mono: Could not find 'vips_blend_mode_get_type' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_blend_mode_get_type'.
   2743 Mono: Probing 'vips_blend_mode_get_typeA'.
   2744 Mono: Could not find 'vips_blend_mode_get_typeA' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_blend_mode_get_typeA'.
   2745 Mono: Probing 'vips_blend_mode_get_typeA'.
   2746 Mono: Could not find 'vips_blend_mode_get_typeA' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_blend_mode_get_typeA'.
   2747 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2748 Mono: Searching for 'g_object_unref'.
   2749 Mono: Probing 'g_object_unref'.
   2750 Mono: Found as 'g_object_unref'.
   2751 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2752 Mono: Searching for 'g_value_init'.
   2753 Mono: Probing 'g_value_init'.
   2754 Mono: Found as 'g_value_init'.
   2755 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2756 Mono: Searching for 'g_object_set_property'.
   2757 Mono: Probing 'g_object_set_property'.
   2758 Mono: Found as 'g_object_set_property'.
   2759 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2760 Mono: Searching for 'g_type_fundamental'.
   2761 Mono: Probing 'g_type_fundamental'.
   2762 Mono: Found as 'g_type_fundamental'.
   2763 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2764 Mono: Searching for 'g_value_set_boolean'.
   2765 Mono: Probing 'g_value_set_boolean'.
   2766 Mono: Found as 'g_value_set_boolean'.
   2767 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2768 Mono: Searching for 'g_value_set_int'.
   2769 Mono: Probing 'g_value_set_int'.
   2770 Mono: Found as 'g_value_set_int'.
   2771 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2772 Mono: Searching for 'g_value_set_uint64'.
   2773 Mono: Probing 'g_value_set_uint64'.
   2774 Mono: Found as 'g_value_set_uint64'.
   2775 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2776 Mono: Searching for 'g_value_set_double'.
   2777 Mono: Probing 'g_value_set_double'.
   2778 Mono: Found as 'g_value_set_double'.
   2779 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2780 Mono: Searching for 'g_value_set_enum'.
   2781 Mono: Probing 'g_value_set_enum'.
   2782 Mono: Found as 'g_value_set_enum'.
   2783 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2784 Mono: Searching for 'g_value_set_flags'.
   2785 Mono: Probing 'g_value_set_flags'.
   2786 Mono: Found as 'g_value_set_flags'.
   2787 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2788 Mono: Searching for 'g_value_set_string'.
   2789 Mono: Probing 'g_value_set_string'.
   2790 Mono: Found as 'g_value_set_string'.
   2791 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2792 Mono: Searching for 'vips_value_set_ref_string'.
   2793 Mono: Probing 'vips_value_set_ref_string'.
   2794 Mono: Found as 'vips_value_set_ref_string'.
   2795 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2796 Mono: Searching for 'g_value_set_object'.
   2797 Mono: Probing 'g_value_set_object'.
   2798 Mono: Found as 'g_value_set_object'.
   2799 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2800 Mono: Searching for 'g_type_name'.
   2801 Mono: Probing 'g_type_name'.
   2802 Mono: Found as 'g_type_name'.
   2803 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2804 Mono: Searching for 'vips_value_set_array_int'.
   2805 Mono: Probing 'vips_value_set_array_int'.
   2806 Mono: Found as 'vips_value_set_array_int'.
   2807 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2808 Mono: Searching for 'vips_value_set_array_double'.
   2809 Mono: Probing 'vips_value_set_array_double'.
   2810 Mono: Found as 'vips_value_set_array_double'.
   2811 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2812 Mono: Searching for 'vips_value_set_array_image'.
   2813 Mono: Probing 'vips_value_set_array_image'.
   2814 Mono: Found as 'vips_value_set_array_image'.
   2815 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2816 Mono: Searching for 'vips_value_get_array_image'.
   2817 Mono: Probing 'vips_value_get_array_image'.
   2818 Mono: Found as 'vips_value_get_array_image'.
   2819 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2820 Mono: Searching for 'g_object_ref'.
   2821 Mono: Probing 'g_object_ref'.
   2822 Mono: Found as 'g_object_ref'.
   2823 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2824 Mono: Searching for 'g_value_set_boxed'.
   2825 Mono: Probing 'g_value_set_boxed'.
   2826 Mono: Found as 'g_value_set_boxed'.
   2827 Mono: DllImport attempting to load: 'libglib-2.0.so.0'.
   2828 Mono: DllImport error loading library '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libglib-2.0.so.0': '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libglib-2.0.so.0: cannot open shared object file: No such file or directory'.
   2829 Mono: DllImport error loading library '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libglib-2.0.so.0.so': '/home/jsm174/git/r/VisualPinball.Engine/VisualPinball.Unity/Vendor/linux-x64/libglib-2.0.so.0.so: cannot open shared object file: No such file or directory'.
   2830 Mono: DllImport error loading library '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libglib-2.0.so.0': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libglib-2.0.so.0: cannot open shared object file: No such file or directory'.
   2831 Mono: DllImport error loading library '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libglib-2.0.so.0.so': '/home/jsm174/Unity/Hub/Editor/2020.1.0b16/lib/libglib-2.0.so.0.so: cannot open shared object file: No such file or directory'.
   2832 Mono: DllImport loaded library 'libglib-2.0.so.0'.
   2833 Mono: DllImport searching in: 'libglib-2.0.so.0' ('libglib-2.0.so.0').
   2834 Mono: Searching for 'g_malloc'.
   2835 Mono: Probing 'g_malloc'.
   2836 Mono: Found as 'g_malloc'.
   2837 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2838 Mono: Searching for 'vips_value_set_blob_free'.
   2839 Mono: Probing 'vips_value_set_blob_free'.
   2840 Mono: Could not find 'vips_value_set_blob_free' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_value_set_blob_free'.
   2841 Mono: Probing 'vips_value_set_blob_free'.
   2842 Mono: Could not find 'vips_value_set_blob_free' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_value_set_blob_free'.
   2843 Mono: Probing 'vips_value_set_blob_freeA'.
   2844 Mono: Could not find 'vips_value_set_blob_freeA' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_value_set_blob_freeA'.
   2845 Mono: Probing 'vips_value_set_blob_freeA'.
   2846 Mono: Could not find 'vips_value_set_blob_freeA' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_value_set_blob_freeA'.
   2847 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2848 Mono: Searching for 'vips_value_set_blob'.
   2849 Mono: Probing 'vips_value_set_blob'.
   2850 Mono: Found as 'vips_value_set_blob'.
   2851 Mono: DllImport searching in: 'libglib-2.0.so.0' ('libglib-2.0.so.0').
   2852 Mono: Searching for 'g_free'.
   2853 Mono: Probing 'g_free'.
   2854 Mono: Found as 'g_free'.
   2855 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2856 Mono: Searching for 'g_value_unset'.
   2857 Mono: Probing 'g_value_unset'.
   2858 Mono: Found as 'g_value_unset'.
   2859 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2860 Mono: Searching for 'g_object_get_property'.
   2861 Mono: Probing 'g_object_get_property'.
   2862 Mono: Found as 'g_object_get_property'.
   2863 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2864 Mono: Searching for 'g_value_get_boolean'.
   2865 Mono: Probing 'g_value_get_boolean'.
   2866 Mono: Found as 'g_value_get_boolean'.
   2867 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2868 Mono: Searching for 'g_value_get_int'.
   2869 Mono: Probing 'g_value_get_int'.
   2870 Mono: Found as 'g_value_get_int'.
   2871 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2872 Mono: Searching for 'g_value_get_uint64'.
   2873 Mono: Probing 'g_value_get_uint64'.
   2874 Mono: Found as 'g_value_get_uint64'.
   2875 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2876 Mono: Searching for 'g_value_get_double'.
   2877 Mono: Probing 'g_value_get_double'.
   2878 Mono: Found as 'g_value_get_double'.
   2879 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2880 Mono: Searching for 'g_value_get_enum'.
   2881 Mono: Probing 'g_value_get_enum'.
   2882 Mono: Found as 'g_value_get_enum'.
   2883 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2884 Mono: Searching for 'g_value_get_flags'.
   2885 Mono: Probing 'g_value_get_flags'.
   2886 Mono: Found as 'g_value_get_flags'.
   2887 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2888 Mono: Searching for 'g_value_get_string'.
   2889 Mono: Probing 'g_value_get_string'.
   2890 Mono: Found as 'g_value_get_string'.
   2891 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2892 Mono: Searching for 'vips_value_get_ref_string'.
   2893 Mono: Probing 'vips_value_get_ref_string'.
   2894 Mono: Found as 'vips_value_get_ref_string'.
   2895 Mono: DllImport searching in: 'libgobject-2.0.so.0' ('libgobject-2.0.so.0').
   2896 Mono: Searching for 'g_value_get_object'.
   2897 Mono: Probing 'g_value_get_object'.
   2898 Mono: Found as 'g_value_get_object'.
   2899 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2900 Mono: Searching for 'vips_value_get_array_int'.
   2901 Mono: Probing 'vips_value_get_array_int'.
   2902 Mono: Found as 'vips_value_get_array_int'.
   2903 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2904 Mono: Searching for 'vips_value_get_array_double'.
   2905 Mono: Probing 'vips_value_get_array_double'.
   2906 Mono: Found as 'vips_value_get_array_double'.
   2907 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2908 Mono: Searching for 'vips_value_get_blob'.
   2909 Mono: Probing 'vips_value_get_blob'.
   2910 Mono: Found as 'vips_value_get_blob'.
   2911 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2912 Mono: Searching for 'vips_image_hasalpha'.
   2913 Mono: Probing 'vips_image_hasalpha'.
   2914 Mono: Could not find 'vips_image_hasalpha' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_image_hasalpha'.
   2915 Mono: Probing 'vips_image_hasalpha'.
   2916 Mono: Could not find 'vips_image_hasalpha' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_image_hasalpha'.
   2917 Mono: Probing 'vips_image_hasalphaA'.
   2918 Mono: Could not find 'vips_image_hasalphaA' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_image_hasalphaA'.
   2919 Mono: Probing 'vips_image_hasalphaA'.
   2920 Mono: Could not find 'vips_image_hasalphaA' due to '/usr/lib/x86_64-linux-gnu/libvips.so: undefined symbol: vips_image_hasalphaA'.
   2921 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2922 Mono: Searching for 'vips_image_get'.
   2923 Mono: Probing 'vips_image_get'.
   2924 Mono: Found as 'vips_image_get'.
   2925 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2926 Mono: Searching for 'vips_enum_nick'.
   2927 Mono: Probing 'vips_enum_nick'.
   2928 Mono: Found as 'vips_enum_nick'.
   2929 Mono: DllImport searching in: 'libvips.so' ('libvips.so').
   2930 Mono: Searching for 'vips_enum_from_nick'.
   2931 Mono: Probing 'vips_enum_from_nick'.
   2932 Mono: Found as 'vips_enum_from_nick'.

@kleisauke kleisauke added the question Further information is requested label Aug 14, 2020
@kleisauke
Copy link
Owner

Hello @jsm174,

Sorry for the delay, I was quite busy with other projects.

I could not reproduce this on my Fedora machine with Unity 2020.1.2. I followed this tutorial to include the Unity project as a package. After that, I had to fix the *.meta files of the native Linux DLLs, see:
freezy/VisualPinball.Engine@master...kleisauke:linux

With the above commit, the example project could be built and executed. Do I need to import a VPX file to reproduce it? If so, is there a sample file I can use?

@jsm174
Copy link
Author

jsm174 commented Aug 14, 2020

@kleisauke, no worries. Thank you for looking into this!

Correct, you will need to import a VPX file before any NetVips calls are executed.

You should be able to grab the VPX table here:
https://vpdb.io/games/mm/releases/e2rydboew

@jsm174
Copy link
Author

jsm174 commented Aug 14, 2020

One other question, on your PR. (had something similar, but didn't submit since it wasn't fully working).

Just curious, did Unity's Editor UI allow you to modify the *.so.* settings, or did you manually edit them after they were generated? I could not get the UI to show any linux settings when the *.so files had extensions.

@kleisauke
Copy link
Owner

kleisauke commented Aug 14, 2020

I'm able to import the above linked VPX file (using the linux branch) without any problems (screenshot). Here are some things that I noticed:

  • I don't have Mono installed on my Fedora PC. Perhaps Unity uses a built-in Mono distribution?
  • Unity was installed from the Unity Hub.
  • I did not make any changes to the Unity dllmap config file.
  • libvips has been removed prior these tests to ensure that it chooses the binaries from NetVips.Native.linux-x64.

If you want, I can also test this on Ubuntu 18.04 running in a VM.

One other question, on your PR. (had something similar, but didn't submit since it wasn't fully working).

I haven't submitted a PR either. Feel free to use these changes!

Just curious, did Unity's Editor UI allow you to modify the *.so.* settings, or did you manually edit them after they were generated? I could not get the UI to show any linux settings when the *.so files had extensions.

I manually modified these *.meta files by comparing it against the files from the Vendor/osx-x64 directory.

@freezy
Copy link

freezy commented Aug 14, 2020

A PR would be wonderful!

Thanks guys for looking into this.

@jsm174
Copy link
Author

jsm174 commented Aug 14, 2020

Thanks. Just to follow up

Unity does have it's own mono installation.

Two questions

  1. you did not modify .... etc/mono/config?
  2. no exceptions are showing in the console or ~/.config/unity3d/Editor.log

I'm going to try again in Unity 2020.1.2..

@jsm174
Copy link
Author

jsm174 commented Aug 14, 2020

So I just had a chance to test Unity 2020.1.2f1 in Ubuntu 18.04. Using your branch, without any modifications to
~/Unity/Hub/Editor/2020.1.2f1/Editor/Data/MonoBleedingEdge/etc/mono/config,

Here is what I see:

Screenshot from 2020-08-14 17-08-24

@kleisauke
Copy link
Owner

I somehow missed those errors in the console, sorry. I also see this crash with commit kleisauke/VisualPinball.Engine@b19c2c2 (which removes the need for those DllMap configuration files). Unfortunately, there is not much that NetVips can do for this.

This crash happens because the GType register is in a flat global namespace. It can conflict when another GLib instance (running in the same process) registers a GObject type (for e.g. gchar). As far as I know, there are three ways to resolve this issue:

  1. Make the executable (i.e. the Visual Pinball Engine importer) self-contained to ensure that it doesn't conflict with other dependencies requiring GLib (i.e. Mono / Unity);
  2. Install libvips via the package manager (this ensures that the system-wide GLib dependency is used);
  3. Compile libvips manually.

Making the importer self-contained (1) might be the best option if you want to use the pre-built libvips binaries. Python for Unity has a out-of-process API that could perhaps be used, I'm not sure if there is a similar API available for C#.

Alternatively, you could parse the VPX files with an intermediate step. I noticed that NetVips is only used to calculate the opaque/translucent/transparent stats, perhaps you could write that to a JSON file and have Unity import that? The advantage of this approach is that you can easily perform this step on any platform. For example, I'm currently working on WebAssembly bindings for libvips, so that you can run it in the browser without the hassle of installing pre-built binaries, see:
wasm-vips
(Sneak preview, will be released soon)

Install libvips via the package manager is another option (2). The only downside is that on some distributions the libvips package is quite old. For example, Debian's policy is never to update packages (except for security fixes and critical bugs) because they prioritize stability. If you want a system with up-to-date binaries, you need to pick a different Linux or compile libvips manually (3).

@freezy
Copy link

freezy commented Aug 17, 2020

Do we know what registers GType in a flat global namespace? Is it libvips itself, hence solution 3) to recompile it in a separate namespace?

@jsm174
Copy link
Author

jsm174 commented Aug 17, 2020

With a fresh project in 2020.1.2f1, (vpe package NOT installed), I looked at open files for the Unity process:

➜  ~ lsof -p 5197 | grep -i glib
Unity   5197 jsm174  mem       REG                8,1   1137968   9175384 /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5600.4
➜  ~ lsof -p 5197 | grep -i gobject
Unity   5197 jsm174  mem       REG                8,1    342072   9175408 /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.5600.4
Unity   5197 jsm174  mem       REG                8,1     34720   9182915 /usr/lib/x86_64-linux-gnu/libcairo-gobject.so.2.11510.0
➜  ~ lsof -p 5197 | grep -i bleeding
Unity   5197 jsm174  mem       REG                8,1   3138048    918958 /home/jsm174/Unity/Hub/Editor/2020.1.2f1/Editor/Data/MonoBleedingEdge/lib/mono/unityjit/System.Xml.dll
Unity   5197 jsm174  mem       REG                8,1    114688    918758 /home/jsm174/Unity/Hub/Editor/2020.1.2f1/Editor/Data/MonoBleedingEdge/lib/mono/unityjit/System.Net.Http.dll
Unity   5197 jsm174  mem       REG                8,1     84992    918824 /home/jsm174/Unity/Hub/Editor/2020.1.2f1/Editor/Data/MonoBleedingEdge/lib/mono/unityjit/Facades/netstandard.dll
Unity   5197 jsm174  mem       REG                8,1   2750464    918782 /home/jsm174/Unity/Hub/Editor/2020.1.2f1/Editor/Data/MonoBleedingEdge/lib/mono/unityjit/System.dll
Unity   5197 jsm174  mem       REG                8,1    119296    918738 /home/jsm174/Unity/Hub/Editor/2020.1.2f1/Editor/Data/MonoBleedingEdge/lib/mono/unityjit/System.Xml.Linq.dll
Unity   5197 jsm174  mem       REG                8,1   1046016    918955 /home/jsm174/Unity/Hub/Editor/2020.1.2f1/Editor/Data/MonoBleedingEdge/lib/mono/unityjit/System.Core.dll
Unity   5197 jsm174  mem       REG                8,1   3549408    917906 /home/jsm174/Unity/Hub/Editor/2020.1.2f1/Editor/Data/MonoBleedingEdge/MonoEmbedRuntime/libmonobdwgc-2.0.so
Unity   5197 jsm174  mem       REG                8,1   4072448    918766 /home/jsm174/Unity/Hub/Editor/2020.1.2f1/Editor/Data/MonoBleedingEdge/lib/mono/unityjit/mscorlib.dll

fwiw:

/home/jsm174/Unity/Hub/Editor/2020.1.2f1/Editor/Data/MonoBleedingEdge/etc/mono/config:

        <dllmap dll="libglib-2.0" target="libglib-2.0.so.0" os="!windows"/>
        <dllmap dll="libgobject-2.0" target="libgobject-2.0.so.0" os="!windows"/>

Also, I did the same test on the Mac:

➜  mono lsof -p 38018 | grep -i glib
➜  mono lsof -p 38018 | grep -i gobject
➜  mono lsof -p 38018 | grep -i bleeding
Unity   38018 jmillard  txt       REG                1,4   4730384            21918712 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/MonoEmbedRuntime/osx/libmonobdwgc-2.0.dylib
Unity   38018 jmillard  txt       REG                1,4   4072448            21922876 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/mscorlib.dll
Unity   38018 jmillard  txt       REG                1,4   1046016            21922737 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/System.Core.dll
Unity   38018 jmillard  txt       REG                1,4   2750464            21922869 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/System.dll
Unity   38018 jmillard  txt       REG                1,4    119296            21922867 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/System.Xml.Linq.dll
Unity   38018 jmillard  txt       REG                1,4   3138048            21922868 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/System.Xml.dll
Unity   38018 jmillard  txt       REG                1,4     84992            21923011 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/Facades/netstandard.dll
Unity   38018 jmillard  txt       REG                1,4    114688            21922760 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/System.Net.Http.dll

@jsm174
Copy link
Author

jsm174 commented Aug 21, 2020

@kleisauke Hello again. I had a chance to look at this some more.

I decided to make a clone of NetVips for Unity: https://github.com/jsm174/net-vips-unity

Basically we

  1. added abstract GLib, GObject, and Vips classes in Interop
  2. added static proxies in Internal that get initialized based on OSPlatform and select correct libs.

This allowed us to not have to make any code changes to anything inside of root NetVips directory. It also gets us around dllmap issues. (we really don't want people having to edit their Unity etc/mono/config file).

So now we should be able to include native dlls that are compatible with Unity.

Currently, we are using your latest native dlls (https://github.com/jsm174/net-vips-unity/tree/master/deps/libvips)

Our current observations are:

  • OSX is finding copies of libgobject-2.0.0.dylib and libglib-2.0.0.dylib in /Library/Frameworks/Mono.framework/Libraries/ which doesn't seem compatible:

https://github.com/jsm174/net-vips-unity/runs/1014100623?check_suite_focus=true#step:6:286

  • Linux has an issue when trying to load libvips.so.42: undefined symbol: g_thread_proxy

https://github.com/jsm174/net-vips-unity/runs/1014100593?check_suite_focus=true#step:6:157

@kleisauke
Copy link
Owner

Do we know what registers GType in a flat global namespace? Is it libvips itself, hence solution 3) to recompile it in a separate namespace?

Solution 3) is similar to 2) by ensuring that the system-wide GLib dependency is used to avoid conflicts with different GLib's.

Also, I did the same test on the Mac:

➜  mono lsof -p 38018 | grep -i glib
➜  mono lsof -p 38018 | grep -i gobject
➜  mono lsof -p 38018 | grep -i bleeding
Unity   38018 jmillard  txt       REG                1,4   4730384            21918712 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/MonoEmbedRuntime/osx/libmonobdwgc-2.0.dylib
Unity   38018 jmillard  txt       REG                1,4   4072448            21922876 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/mscorlib.dll
Unity   38018 jmillard  txt       REG                1,4   1046016            21922737 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/System.Core.dll
Unity   38018 jmillard  txt       REG                1,4   2750464            21922869 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/System.dll
Unity   38018 jmillard  txt       REG                1,4    119296            21922867 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/System.Xml.Linq.dll
Unity   38018 jmillard  txt       REG                1,4   3138048            21922868 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/System.Xml.dll
Unity   38018 jmillard  txt       REG                1,4     84992            21923011 /Applications/Unity/Hub/Editor/2020.1.2f1/Unity.app/Contents/MonoBleedingEdge/lib/mono/unityjit/Facades/netstandard.dll
Unity   38018 jmillard  txt       REG                1,4    114688            21922760 /Applications/Unity/Hub/Editor/2020.1.

That's interesting! This is probably because Unity decided to not link against Homebrew's GLib. Instead, they seem to provide their own statically linked GLib (which is the same strategy as NetVips). This might be the reason why it works on macOS out-of-the box.

I decided to make a clone of NetVips for Unity: https://github.com/jsm174/net-vips-unity

Basically we

  1. added abstract GLib, GObject, and Vips classes in Interop
  2. added static proxies in Internal that get initialized based on OSPlatform and select correct libs.

This allowed us to not have to make any code changes to anything inside of root NetVips directory. It also gets us around dllmap issues. (we really don't want people having to edit their Unity etc/mono/config file).

I agree that editing the Unity configuration file should not be necessary, but I'm not sure a "hard-fork" for NetVips is desired here. My opinion is that this check has to be done at compile-time, and therefore different DLLs needs to be deployed on different operating systems (i.e. deploying runtimes/linux/lib/netstandard2.0/NetVips.dll on Linux and deploying runtimes/osx/lib/netstandard2.0/NetVips.dll on macOS). See commit kleisauke/VisualPinball.Engine@b19c2c2 how to do this in VPE without forking NetVips.

  • OSX is finding copies of libgobject-2.0.0.dylib and libglib-2.0.0.dylib in /Library/Frameworks/Mono.framework/Libraries/ which doesn't seem compatible:

https://github.com/jsm174/net-vips-unity/runs/1014100623?check_suite_focus=true#step:6:286

That's curious, I've not encountered this error on Travis' macOS runner using the pre-built binaries, see:
https://travis-ci.org/github/kleisauke/net-vips/jobs/709166981
(although this build crashed due to mono/mono#13813)

Perhaps you need to set DYLD_LIBRARY_PATH to the output directory? See for example:

if [ "$(uname)" == "Darwin" ]; then
export DYLD_LIBRARY_PATH=$(dirname "$DLL_FILE")${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
export LD_LIBRARY_PATH=$(dirname "$DLL_FILE")${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
fi

  • Linux has an issue when trying to load libvips.so.42: undefined symbol: g_thread_proxy

https://github.com/jsm174/net-vips-unity/runs/1014100593?check_suite_focus=true#step:6:157

g_thread_proxy seems to be an internal symbol, so I'm not sure why this is happening.

@jsm174
Copy link
Author

jsm174 commented Aug 23, 2020

I agree that editing the Unity configuration file should not be necessary, but I'm not sure a "hard-fork" for NetVips is desired here. My opinion is that this check has to be done at compile-time, and therefore different DLLs needs to be deployed on different operating systems (i.e. deploying runtimes/linux/lib/netstandard2.0/NetVips.dll on Linux and deploying runtimes/osx/lib/netstandard2.0/NetVips.dll on macOS). See commit kleisauke/VisualPinball.Engine@b19c2c2 how to do this in VPE without forking NetVips.

Unity does not use .csproj files. It basically recompiles any .cs file it finds. Which is why if we want to make one package anyone can download regardless of OS, and have it find the correct dll file names, it has to be done at runtime. (Fwiw, the meta files you modified control if the Plugins get loaded by Unity)

I did end up working on the NetVips.Unity some more, trying to compile the native libraries, like sharp libvips: https://github.com/lovell/sharp-libvips/blob/master/build/lin.sh#L359

Everything is compiling and testing successfully for all platforms.

https://github.com/jsm174/net-vips-unity/actions/runs/220209751

The final hurdle now is using the NetVips.Unity.dll back inside Visual Pinball Engine. I'm getting
https://github.com/jsm174/VisualPinball.Engine/runs/1017265363?check_suite_focus=true#step:6:249

Mono: Searching for 'vips_foreign_find_load_buffer'.
Mono: Probing 'vips_foreign_find_load_buffer'.
Mono: Found as 'vips_foreign_find_load_buffer'.

(process:1122): GLib-GObject-WARNING **: 02:07:47.933: cannot retrieve class for invalid (unclassed) type '<invalid>'

(process:1122): GLib-GObject-WARNING **: 02:07:47.933: invalid class cast from (NULL) pointer to 'VipsObject'

(process:1122): GLib-GObject-WARNING **: 02:07:47.933: invalid class cast from (NULL) pointer to 'VipsObject'

Testing it locally, I'm seeing:

{System.TypeInitializationException: The type initializer for 'System.MemoryExtensions' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
  at System.MemoryExtensions..cctor () [0x00000] in <16786cfd571c4686983021cfcee42fb4>:0 
   --- End of inner exception stack trace ---
  at NetVips.Image.FindLoadBuffer (System.Byte[] data) [0x00000] in <29d21f83d85e4edab1898cf537836d71>:0 
  at NetVips.Image.NewFromBuffer (System.Byte[] data, System.String strOptions, System.String access, System.Nullable`1[T] fail, NetVips.VOption kwargs) [0x00000] in <29d21f83d85e4edab1898cf537836d71>:0 
  at VisualPinball.Engine.VPT.Texture.GetImage () [0x0000d] in /Users/jmillard/git/VisualPinball.Engine/VisualPinball.Engine/VPT/Texture.cs:136 }
	base: {System.SystemException}
	TypeName: "System.MemoryExtensions"
	_typeName: "System.MemoryExtensions"

I'll keep working on it...

@kleisauke
Copy link
Owner

kleisauke commented Aug 23, 2020

Unity does not use .csproj files. It basically recompiles any .cs file it finds. Which is why if we want to make one package anyone can download regardless of OS, and have it find the correct dll file names, it has to be done at runtime. (Fwiw, the meta files you modified control if the Plugins get loaded by Unity)

Ah, I didn't know that. If it recompiles every .cs file, how about using Unity's preprocessor directives? I had a quick go, see commit e13972e on the unity branch.

This commit basically removes all dependencies of NetVips and merges the Libraries.*.cs files into a single class, see:

#if UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX
// We can safely define all these variables as `libvips.so.42` since
// DLLImport uses dlsym() on Linux. This function also searches for named
// symbols in the dependencies of the shared library. Therefore, we can
// provide libvips as a single shared library with all dependencies
// statically linked without breaking compatibility with shared builds
// (i.e. what is usually installed via package managers).
internal const string GLib = "libvips.so.42",
GObject = "libvips.so.42",
Vips = "libvips.so.42";
#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
// We can safely define all these variables as `libvips.42.dylib` since
// DLLImport uses dlsym() on macOS. This function also searches for named
// symbols in the dependencies of the shared library. Therefore, we can
// provide libvips as a single shared library with all dependencies
// statically linked without breaking compatibility with shared builds
// (i.e. what is usually installed via package managers).
internal const string GLib = "libvips.42.dylib",
GObject = "libvips.42.dylib",
Vips = "libvips.42.dylib";
#elif UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
// We cannot define all these variables as `libvips-42.dll` without
// breaking compatibility with the shared Windows build. Therefore,
// we always ship at least 3 DLLs.
internal const string GLib = "libglib-2.0-0.dll",
GObject = "libgobject-2.0-0.dll",
Vips = "libvips-42.dll";
#else
#error "Unknown target platform"
#endif

Feel free to use these changes (it could perhaps be useful as a git submodule).

Note that you must call NetVips.Init() by yourself within this branch, since the ModuleInit.Fody dependency was also removed.

The final hurdle now is using the NetVips.Unity.dll back inside Visual Pinball Engine. I'm getting
https://github.com/jsm174/VisualPinball.Engine/runs/1017265363?check_suite_focus=true#step:6:249

Mono: Searching for 'vips_foreign_find_load_buffer'.
Mono: Probing 'vips_foreign_find_load_buffer'.
Mono: Found as 'vips_foreign_find_load_buffer'.

(process:1122): GLib-GObject-WARNING **: 02:07:47.933: cannot retrieve class for invalid (unclassed) type '<invalid>'

(process:1122): GLib-GObject-WARNING **: 02:07:47.933: invalid class cast from (NULL) pointer to 'VipsObject'

(process:1122): GLib-GObject-WARNING **: 02:07:47.933: invalid class cast from (NULL) pointer to 'VipsObject'

It looks like vips_init() / NetVips.Init() was not called.

@jsm174
Copy link
Author

jsm174 commented Aug 24, 2020

@kleisauke - Thank you again for all your help!

Just so I'm understanding, if we were to use the preprocessing directives approach, we would take your Unity branch as a submodule and Unity would build its own NetVips? (hence why you removed the dependencies?)

I did take all your changes from the unity branch and put them in NetVips.Unity nuget. (https://github.com/jsm174/net-vips-unity/commit/1955518ba85b0bb43635f192108fd7d13fd1bcab#diff-8549537d20bf5bc51ac2abf3445d5961R276)

(Having the dependencies removed helped out. Otherwise I would have had to repack with ILRepack)

I then added a NetVips.NetVips.Init() to Visual Pinball Engine, and it all worked!

OSX:
https://github.com/jsm174/VisualPinball.Engine/runs/1019827402#step:6:247

Linux:
https://github.com/jsm174/VisualPinball.Engine/runs/1019827415#step:6:217

@kleisauke
Copy link
Owner

You should be careful with distributing libvips that links against system libraries. It usually works when used on the same distro on which it is compiled, but it can easily break if used on other distros (or even older versions of the same distro). That's why NetVips (and sharp) distributes libvips with every dependency statically-linked. This also ensures that newer dependencies can easily be incorporated (for e.g. libspng).

For Ubuntu a PPA would be more appropriate, see libvips/libvips#987. For macOS, you could use libvips from Homebrew or use the NetVips.Native.osx-x64 binaries (see below).

Just so I'm understanding, if we were to use the preprocessing directives approach, we would take your Unity branch as a submodule and Unity would build its own NetVips? (hence why you removed the dependencies?)

Correct. This to avoid having to maintain a separate fork.

I did take all your changes from the unity branch and put them in NetVips.Unity nuget.

As long as you keep this package unlisted, I'm fine with it.

(Having the dependencies removed helped out. Otherwise I would have had to repack with ILRepack)

Note that removing the System.Memory dependency might have a negative impact on performance because ArrayPool<T> and Span<T> could not be utilized. Hopefully soon Unity.Collections v0.11.0 will be released, which should also fix this issue, see:
https://forum.unity.com/threads/please-update-com-unity-collections-reference-of-system-runtime-compilerservices-unsafe.732056/#post-5972735

I then added a NetVips.NetVips.Init() to Visual Pinball Engine, and it all worked!

It makes more sense to move this to the constructor to prevent libvips from being initialized several times (although libvips has protection against vips_init being called more than once).

  • OSX is finding copies of libgobject-2.0.0.dylib and libglib-2.0.0.dylib in /Library/Frameworks/Mono.framework/Libraries/ which doesn't seem compatible:

https://github.com/jsm174/net-vips-unity/runs/1014100623?check_suite_focus=true#step:6:286

After having taken a closer look, it's because you specified these libraries in your P/Invoke methods. Try changing these libraries to libvips.42.dylib instead (and use the binaries from the NetVips.Native.osx-x64 package).

@jsm174
Copy link
Author

jsm174 commented Aug 24, 2020

You should be careful with distributing libvips that links against system libraries. It usually works when used on the same distro on which it is compiled, but it can easily break if used on other distros (or even older versions of the same distro). That's why NetVips (and sharp) distributes libvips with every dependency statically-linked. This also ensures that newer dependencies can easily be incorporated (for e.g. libspng).

Yes, this crossed my mind several times over the weekend 😃 . I just wanted to get something working before I could start testing other scenarios.

If I end up using the libs here: https://github.com/lovell/sharp-libvips/releases/tag/v8.10.0 (which are your NetVips.Native ones), aren't I still going to have the gchar issues that started this whole thread?

Note that removing the System.Memory dependency might have a negative impact on performance because ArrayPool and Span could not be utilized. Hopefully soon Unity.Collections v0.11.0 will be released, which should also fix this issue, see:
https://forum.unity.com/threads/please-update-com-unity-collections-reference-of-system-runtime-compilerservices-unsafe.732056/#post-5972735

I'm going to go put these dependencies back in as we are now using the latest Unity.Collections. (I had posted in that thread before). We were using ILRepack on NetVips, which basically included and internalized System.Memory and CompilerServices in the NetVips.dll.

It makes more sense to move this to the constructor to prevent libvips from being initialized several times (although libvips has protection against vips_init being called more than once).

Yes, this was just a quick test for me to see if it would work.

Again, I truly appreciate the help and patience!

@jsm174
Copy link
Author

jsm174 commented Aug 24, 2020

Updated NetVips.Unity to 0.0.4.

  • Reverted removing the System.Memory dependencies.
  • Updated Linux to use libvips.so.42 for libglib + libgobject
  • Updated OSX to use libvips.42.dylib for libglib + libgobject
  • Added NetVips.Init() inside of static proxies, (still not best place, but done once, and VPE will not have to explicitly call)
  • Repack NetVips.Unity.dll with ILRepack, internalizing dependencies
  • Updated all native libraries to v8.10.0 prerelease (https://github.com/lovell/sharp-libvips/releases/tag/v8.10.0)

All pipelines pass: (https://github.com/jsm174/net-vips-unity/actions/runs/222260220)


Updated Visual Pinball Engine to use new NetVips.Unity to 0.0.4 (https://github.com/jsm174/VisualPinball.Engine/tree/net-vips-unity-2)

All pipelines pass: (https://github.com/jsm174/VisualPinball.Engine/runs/1021784269)

Running in actual Unity:

  • Win - works
  • OSX - works
  • Linux - original gchar issue

So for now, I can only see a custom compiled libvips.so.42, using distro's glib and gobject?

VisualPinball.Unity.Editor.VpxMenuImporter:ImportVpxEditorMemory(MenuCommand) (at /home/jsm174/dd/VisualPinball.Engine/VisualPinball.Unity/VisualPinball.Unity.Editor/Import/VpxMenuImporter.cs:16)

(Filename: /home/jsm174/dd/VisualPinball.Engine/VisualPinball.Unity/VisualPinball.Unity/Common/UnityTarget.cs Line: 27)


(Unity:2861): GLib-GObject-WARNING **: 11:05:22.874: cannot register existing type 'gchar'
**
GLib-GObject:ERROR:../gobject/gvaluetypes.c:454:_g_value_types_init: assertion failed: (type == G_TYPE_CHAR)
Caught fatal signal - signo:6 code:-6 errno:0 addr:0x3e800000b2d
Obtained 91 stack frames.
#0  0x007f50134138a0 in funlockfile
#1  0x007f501304ef47 in gsignal
#2  0x007f50130508b1 in abort
#3  0x007f5014220315 in g_assertion_message
#4  0x007f501422037a in g_assertion_message_expr
#5  0x007f4e35b03abc in _g_value_types_init
#6  0x007f4e352a3213 in _init
#7  0x007f501e20a783 in _dl_rtld_di_serinfo
#8  0x007f501e20f24f in _dl_find_dso_for_object
#9  0x007f501317751f in _dl_catch_exception
#10 0x007f501e20e81a in _dl_find_dso_for_object
#11 0x007f5017812f96 in (Unknown)
#12 0x007f501317751f in _dl_catch_exception
#13 0x007f50131775af in _dl_catch_error
#14 0x007f5017813745 in dlerror
#15 0x007f5017813051 in dlopen
#16 0x007f4ecca9e68e in mono_dl_open
#17 0x007f4ecca1b549 in mono_jit_info_get_method
#18 0x007f4ecca1c5c8 in mono_lookup_pinvoke_call
#19 0x007f4ecca2f59b in mono_marshal_string_to_utf16
#20 0x007f4ecc8f04c2 in mono_set_break_policy
#21 0x007f4ecc8d5254 in _init
#22 0x007f4ecc8d6ccc in _init
#23 0x007f4ecc8da9c2 in mono_print_method_from_ip
#24 0x007f4ecc95a542 in mono_print_thread_dump_from_ctx
#25 0x007f4ecc95aaad in mono_print_thread_dump_from_ctx
#26 0x00000040ff6793 in (Unknown)
#27 0x00000040d97c21 in NetVips.Internal.Vips:Init (string)
#28 0x007f4ecc8dba75 in mono_print_method_from_ip
#29 0x007f4ecca4af84 in mono_perfcounter_foreach
#30 0x007f4ecca4db19 in mono_object_get_class
#31 0x007f4ecc8d718e in _init
#32 0x007f4ecc8da9c2 in mono_print_method_from_ip
#33 0x007f4ecc95a542 in mono_print_thread_dump_from_ctx
#34 0x007f4ecc95a871 in mono_print_thread_dump_from_ctx
#35 0x00000040ff5393 in (Unknown)
#36 0x00000040d97bb4 in NetVips.NetVips:Init ()
#37 0x007f4ecc8dba75 in mono_print_method_from_ip

@kleisauke
Copy link
Owner

After some investigation, I think I have found a solution for this issue! See commit kleisauke/VisualPinball.Engine@47ccb5b. Could you try the linux branch again?

I also simplified the implementation of including different DLLs for different OSes, see:
freezy/VisualPinball.Engine@master...kleisauke:linux

@kleisauke kleisauke added blocked-upstream-dependency Upstream dependency needs to be updated bug Something isn't working and removed question Further information is requested labels Aug 25, 2020
@jsm174
Copy link
Author

jsm174 commented Aug 25, 2020

@kleisauke - Wow. I just gave this a try on my Ubuntu install and it worked!

I'll test the other OS's too and report back!

I'll need to look at your code because I'm curious about the how NetVips is picking up the correct dll filenames now.

EDIT: So I'm looking at the code and I'm seeing unique NetVips.dll's that got copied to each of the Plugins/<runtime> folders. I'm assuming if we get this working, you'll be making new nugets?

➜  Plugins diff linux-x64/NetVips.dll osx-x64/NetVips.dll
Binary files linux-x64/NetVips.dll and osx-x64/NetVips.dll differ
➜  Plugins diff osx-x64/NetVips.dll win-x64/NetVips.dll
Binary files osx-x64/NetVips.dll and win-x64/NetVips.dll differ
➜  Plugins diff win-x64/NetVips.dll win-x86/NetVips.dll
Binary files win-x64/NetVips.dll and win-x86/NetVips.dll differ

Also, I like what you did with the PluginsDeploy target. The only caveat is, before we could build VisualPinball.Engine.csproj on any platform and it would copy over all platform dlls. Now we'll have to compile on each platform and then check for updates to Plugins, and then commit. (I do realize the way the Plugin folder is currently generated may not be ideal).

kleisauke added a commit to kleisauke/libvips-packaging that referenced this issue Aug 26, 2020
@kleisauke
Copy link
Owner

kleisauke commented Aug 26, 2020

Great! Thanks for testing, I'm also glad it works now, phew! 😅

EDIT: So I'm looking at the code and I'm seeing unique NetVips.dll's that got copied to each of the Plugins/<runtime> folders. I'm assuming if we get this working, you'll be making new nugets?

I'll publish the new NetVips.Native.* NuGet packages somewhere this week.

Also, I like what you did with the PluginsDeploy target. The only caveat is, before we could build VisualPinball.Engine.csproj on any platform and it would copy over all platform dlls. Now we'll have to compile on each platform and then check for updates to Plugins, and then commit.

You can simply do this to ensure that the proper NetVips DLLs are deployed in the corresponding RID directories.

cd VisualPinball.Engine
dotnet build -r win-x64
dotnet build -r win-x86
dotnet build -r osx-x64
dotnet build -r linux-x64

(I do realize the way the Plugin folder is currently generated may not be ideal).

The only thing that might not be ideal is that the (quite large) libvips binaries are checked into version control. The entire plugin directory should probably be placed in .gitignore and only published as part of the release process.

@jsm174
Copy link
Author

jsm174 commented Aug 26, 2020

I'll publish the new NetVips.Native.* NuGet packages somewhere this week.

Fantastic!!

So I'm assuming NetVips.Native.* will now start containing the different NetVips.dlls ? We won't need to import NetVips package?

cd VisualPinball.Engine
dotnet build -r win-x64
dotnet build -r win-x86
dotnet build -r osx-x64
dotnet build -r linux-x64

Perfect. Never even thought about that!

The only thing that might not be ideal is that the (quite large) libvips binaries are checked into version control. The entire plugin directory should probably be placed in .gitignore and only published as part of the release process.

Agreed, and hopefully that will change in the future. Currently as the project is gaining more interest, table designers are grabbing the latest from the repo and adding directly to Unity - so the DLLs need to be there. Only the developers are using Visual Studio / Rider - which creates and refreshes that directory.

One last observation, and this may or may not be an issue.. For Windows, in Unity we have to enable the Load on Startup checkbox, otherwise we get DllNotFoundException: libvips-42.dll errors.

Screen Shot 2020-08-26 at 7 47 17 AM

We don't need to do that for any other platform, or even for libminiz-2.1.0.dll in Windows.

@kleisauke
Copy link
Owner

So I'm assuming NetVips.Native.* will now start containing the different NetVips.dlls ? We won't need to import NetVips package?

The NetVips NuGet package contains the DLLs for different runtimes (within the runtimes/linux/lib/netstandard2.0 and runtimes/osx/lib/netstandard2.0 directories) and the NetVips.Native.* NuGet packages contains only the native binaries.

I cannot merge this into one package because users sometimes prefer to use a system-wide installed libvips (for e.g. to support more image formats).

One last observation, and this may or may not be an issue.. For Windows, in Unity we have to enable the Load on Startup checkbox, otherwise we get DllNotFoundException: libvips-42.dll errors.

We don't need to do that for any other platform, or even for libminiz-2.1.0.dll in Windows.

I could reproduce this on my Windows PC. Could you reproduce this with your NetVips.Unity project? If not, it's probably because the module initializer of NetVips (which initializes libvips) is called before libvips-42.dll is loaded/located. Although I'm not sure why this works on Linux and macOS without having to pre-load the native binaries there.

Perhaps adding VisualPinball.Engine/VisualPinball.Unity/Plugins/win-x64 to the PATH environment variable resolves this?

@jsm174
Copy link
Author

jsm174 commented Aug 26, 2020

Apologies, I thought I looked through the nuget before, but I see them now:

Screen Shot 2020-08-26 at 10 39 52 AM

And they already have the correct library names...

I could reproduce this on my Windows PC. Could you reproduce this with your NetVips.Unity project? If not, it's probably because the module initializer of NetVips (which initializes libvips) is called before libvips-42.dll is loaded/located. Although I'm not sure why this works on Linux and macOS without having to pre-load the native binaries there.

Yes, this does also happen with NetVips.Unity.

@kleisauke kleisauke removed the blocked-upstream-dependency Upstream dependency needs to be updated label Aug 26, 2020
@kleisauke
Copy link
Owner

NetVips.Native v8.10.0 is now available. 🎉

I've updated the linux branch to these binaries with commit kleisauke/VisualPinball.Engine@c34b840.

@jsm174
Copy link
Author

jsm174 commented Aug 26, 2020

Awesome. I honestly can't thank you enough.

I will work on getting this back into VPE!

@freezy
Copy link

freezy commented Aug 26, 2020

@kleisauke Cheers man, you're saving the day again :)

Any objections if I merge your branch upstream and add you to the contributors list?

@jsm174
Copy link
Author

jsm174 commented Aug 27, 2020

@kleisauke -

Sorry, but I just noticed one last thing when going through builds.

I was trying to run this on Mac and Linux:

dotnet build -r win-x64
dotnet build -r win-x86
dotnet build -r osx-x64
dotnet build -r linux-x64

In the NetVips.Native.osx-x64.targets and NetVips.Native.linux-x64.targets files there is a condition for

    <ItemGroup Condition="'$(MSBuildRuntimeType)' == 'Mono'">

dotnet must not report itself as 'Mono', as it never copies the native libs to the .bin directory:

https://github.com/jsm174/VisualPinball.Engine/runs/1036413018?check_suite_focus=true#step:5:29

I was trying to switch our github workflows from msbuild to dotnet for OSX and Linux for consistency.
(https://andrewlock.net/using-reference-assemblies-to-build-net-framework-libararies-on-linux-without-mono/)

Should I open a new issue?

@kleisauke
Copy link
Owner

kleisauke commented Aug 27, 2020

Any objections if I merge your branch upstream and add you to the contributors list?

I have no objections.

In the NetVips.Native.osx-x64.targets and NetVips.Native.linux-x64.targets files there is a condition for

    <ItemGroup Condition="'$(MSBuildRuntimeType)' == 'Mono'">

It's only necessary on Mono to copy the files to the output directory. If you switch the TargetFramework to netcoreapp3.1 for the VisualPinball.Engine.Test project you'll notice that libvips.so.42 or libvips.42.dylib is copied automatically, see:
jsm174/VisualPinball.Engine@dotnet-experiment...kleisauke:dotnet-experiment
https://github.com/kleisauke/VisualPinball.Engine/runs/1038595810?check_suite_focus=true

@jsm174
Copy link
Author

jsm174 commented Aug 28, 2020

I thought I had issues running NUnit tests inside of VS Mac, which was why the test projects were at net472. But this works, so I updated freezy/VisualPinball.Engine#164 accordingly.

Thanks again!

@kleisauke
Copy link
Owner

This has been fixed within VPE with freezy/VisualPinball.Engine#170, I'll close this issue.

fwiw, the above mentioned WebAssembly example can be viewed here:
https://kleisauke.github.io/wasm-vips/playground/#histogram

@freezy
Copy link

freezy commented Sep 4, 2020

@kleisauke can I ask a last favor to give your green light to relicense VPE to GPLv3 at freezy/VisualPinball.Engine#159? You're contributor now and we need everybody's authorization. Sorry that it bit you back so quickly ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants