Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug What is the correct way to use .a static libraries in webgl? getting runtime errors

Discussion in 'WebGL' started by DrViJ, Oct 3, 2021.

  1. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
    Hi, i need someones help. The problem is:
    I am trying to use .a library in my project. it is SkiaSharp, that works ok on mac, android, ios, windows. And it has wasm support, but I cant make it work in unity web builds. When I use C# wrapper I get errors:

    First one:
    test.loader.js:1 To use dlopen, you need to use Emscripten's linking support, see https://github.com/kripken/emscripten/wiki/Linking

    and

    test.framework.js.gz:2 DllNotFoundException: Unable to load DLL 'libSkiaSharp': The specified module could not be found.
    at SkiaSharp.SkiaApi.sk_colortype_get_default_8888 () [0x00000] in <00000000000000000000000000000000>:0
    at SkiaSharp.SKImageInfo..cctor () [0x00000] in <00000000000000000000000000000000>:0
    at SkiaSharp.SKBitmap..ctor (System.Int32 width, System.Int32 height, System.Boolean isOpaque) [0x00000] in <00000000000000000000000000000000>:0
    at Test.Start () [0x00000] in <00000000000000000000000000000000>:0
    Rethrow as TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
    at SkiaSharp.SKBitmap..ctor (System.Int32 width, System.Int32 height, System.Boolean isOpaque) [0x00000] in <00000000000000000000000000000000>:0
    at Test.Start () [0x00000] in <00000000000000000000000000000000>:0

    But I have libSkiaSgarp.a library built for wasm, and it works for Uno Platform, but does not for unity.
    Maybe I am doing something wrong?
     
  2. chrischip

    chrischip

    Joined:
    Oct 10, 2021
    Posts:
    2
    having the same issue here
     
    DrViJ likes this.
  3. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    552
    DrViJ likes this.
  4. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
  5. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
    Code (CSharp):
    1. Building Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.js failed with output:
    2. wasm-ld: error: duplicate symbol: jsimd_can_rgb_ycc
    3. >>> defined in /var/folders/18/99jndmds6px_w52xph7yfc_h0000gn/T/tmpo_khbkvaWebGLSupport_ImageConversionModule_Dynamic.a(External_libjpeg-turbo_src_0_j00uw.o)
    4. >>> defined in Assets/Scenes/Plugins/WebGL/libSkiaSharp.a(libjpeg.jsimd_none.o)
    5.  
     
  6. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
    I think that the problem is duplicate of same library (libjpeg) inside libSkiaSharp.a and Unity3d, but I cant find the way how to solve it
     
    De-Panther likes this.
  7. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
  8. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
    First I had problems with libjpg and libpng, conflicting names. So I Created some regex functions and remaned them everywhere in skia (jsimd functions and etc)

    Then I had problems on Linking:
    Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.js: undefined symbol: _ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE17__assign_externalEPKcm (referenced by top-level compiled C/C++ code)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun () (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPlayerWindow.cs:179)

    The reason was my emscripten version (2.0.32),So I downgraded to 2.0.19 (same as Unity 2021.2) and installed Ubuntu 2.0.4 (cause 2.0.19 does not exist for my mac)

    Now it compiles. But I get runtime errors:

    Code (CSharp):
    1.  
    2. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[35775]:0xa659b0
    3. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3667]:0x122e5f
    4. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3668]:0x122f78
    5. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[9093]:0x34de83
    6. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[35429]:0xa3fcfe
    7. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[16989]:0x632db5
    8. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[2786]:0xcab5e
    9. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[16979]:0x63298d
    10. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[20165]:0x782c31
    11. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[26785]:0x923f3b
    12. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[5737]:0x20ca83
    13. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[21613]:0x7a9dd7
    14. at invoke_iiii (http://localhost:49782/Build/skia.framework.js:2:389202)
    15. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[1390]:0x5c05a
    16. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3848]:0x13a31c
    17. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[687]:0x25741
    18. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[34354]:0xa2350d
    19. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[26785]:0x923f3b
    20. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[5737]:0x20ca83
    21. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[21613]:0x7a9dd7
    22. at invoke_iiii (http://localhost:49782/Build/skia.framework.js:2:389202)
    23. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[1390]:0x5c05a
    24. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3848]:0x13a31c
    25. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[687]:0x25741
    26. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[12641]:0x55cc09
    27. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3866]:0x13acb1
    28. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[12823]:0x5620be
    29. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3001]:0xe3a28
    30. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[28620]:0x945350
    31. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[27463]:0x92f9a0
    32. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[5737]:0x20ca83
    33. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[21613]:0x7a9dd7
    34. at invoke_iiii (http://localhost:49782/Build/skia.framework.js:2:389202)
    35. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[1390]:0x5c05a
    36. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[17433]:0x67009c
    37. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[959]:0x32eb5
    38. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[3326]:0x106663
    39. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[25951]:0x8f772c
    40. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[24919]:0x89d6b6
    41. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[23583]:0x7ecc60
    42. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[12154]:0x54768f
    43. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[12154]:0x5476fe
    44. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[10676]:0x458824
    45. at http://localhost:49782/Build/skia.wasm.gz:wasm-function[21608]:0x7a9d99
    46. at browserIterationFunc (http://localhost:49782/Build/skia.framework.js:2:257698)
    47. at callUserCallback (http://localhost:49782/Build/skia.framework.js:2:131767)
    48. at Object.runIter (http://localhost:49782/Build/skia.framework.js:2:133027)
    49. at Browser_mainLoop_runner (http://localhost:49782/Build/skia.framework.js:2:131302)
     
  9. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
    I dont know what to do with it yet. but I am surprised to see skia.was.gz here, cause I do not use gz compression in Unity for now. Can it be a bug?
     
  10. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
    An abnormal situation has occurred: the PlayerLoop internal function has been called recursively. Please contact Customer Support with a sample project so that we can reproduce the problem and troubleshoot it.
     
  11. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
    I found out that it does not fail on development build, and fails on dev build off. I start thinkng there can be a bug. I will investigate this problem and create a reproductable test to make sure
     
  12. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    552
    I don't know what is your use case, but maybe you should try and work with 2 WASM files,
    one for unity, one for the external lib.
    and just share between them the end result.
    It may help you later in case you need large amount of memory
     
    DrViJ likes this.
  13. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
    Very interesting idea, I will investigate it too, but first I will try to check if native lib can be called from C# all inside unity without implementing 2 wasm programs
     
  14. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
    So I made it to work in development build. Now I will try investigate if there is a bug and will provide reproduction project


    2021-11-02 18.26.09.jpg
     
    Last edited: Nov 2, 2021
    De-Panther likes this.
  15. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
    So development build works, and non development does not. I will start the new thread and prepare the repo with repro