microsoft / MapsSDK-Unity

This repository contains samples, documentation, and supporting scripts for Maps SDK, a Microsoft Garage project.
MIT License
648 stars 127 forks source link

WebGL build fails in Unity 2022 #207

Closed natsoragge closed 12 months ago

natsoragge commented 12 months ago

Describe the bug I have a Unity project that supports multiple platforms. We use the Maps SDK for Android and Standalone, but the project can also be built to WebGL, even though the maps functionality is disabled in this platform. Since I upgraded Unity to 2022, the WebGL build stopped working and I get the following errors:

Building Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js failed with output:
error: undefined symbol: BASIS_Transcode (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _BASIS_Transcode may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: JPEGXR_Decompress (referenced by top-level compiled C/C++ code)
warning: _JPEGXR_Decompress may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: JPEGXR_GetCustomData (referenced by top-level compiled C/C++ code)
warning: _JPEGXR_GetCustomData may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: JPEGXR_GetCustomDataSize (referenced by top-level compiled C/C++ code)
warning: _JPEGXR_GetCustomDataSize may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: JPEGXR_GetImageDescription (referenced by top-level compiled C/C++ code)
warning: _JPEGXR_GetImageDescription may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: JPEGXR_GetImageDescriptionSize (referenced by top-level compiled C/C++ code)
warning: _JPEGXR_GetImageDescriptionSize may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: ZSTD_createDCtx (referenced by top-level compiled C/C++ code)
warning: _ZSTD_createDCtx may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: ZSTD_createDDict (referenced by top-level compiled C/C++ code)
warning: _ZSTD_createDDict may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: ZSTD_decompressDCtx (referenced by top-level compiled C/C++ code)
warning: _ZSTD_decompressDCtx may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: ZSTD_decompress_usingDDict (referenced by top-level compiled C/C++ code)
warning: _ZSTD_decompress_usingDDict may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: ZSTD_freeDCtx (referenced by top-level compiled C/C++ code)
warning: _ZSTD_freeDCtx may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: ZSTD_freeDDict (referenced by top-level compiled C/C++ code)
warning: _ZSTD_freeDDict may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: ZSTD_getDecompressedSize (referenced by top-level compiled C/C++ code)
warning: _ZSTD_getDecompressedSize may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: ZSTD_getErrorName (referenced by top-level compiled C/C++ code)
warning: _ZSTD_getErrorName may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: ZSTD_isError (referenced by top-level compiled C/C++ code)
warning: _ZSTD_isError may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
emcc: error: '"C:/Program Files/Unity/Hub/Editor/2022.3.6f1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/node/node.exe" "C:\Program Files\Unity\Hub\Editor\2022.3.6f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\src\compiler.js" C:\Users\user\AppData\Local\Temp\tmpvh7byjl2.json' failed (returned 1)

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

I know the SDK does not support WebGL, but it shouldn't block WebGL builds.

To Reproduce Steps to reproduce the behavior:

  1. Create a new project
  2. Add the Maps SDK package to it
  3. Add an object with a Map Renderer component to the main scene (avoids the package from being stripped)
  4. Try to build for WebGL

Expected behavior The build should work

Screenshots image

Environment (please complete the following information):

Additional context Excluding WebGL from the Runtime asmdef and from Microsoft.Maps.Unity.dll's target platforms seems to fix the build issue, but cause errors in runtime

kircher1 commented 12 months ago

I can offer a quick workaround, which will stub out those functions in the WebGL build so that the build will not fail.

Now the WebGL build should work.

Note however, there will be unnecessary compilation and size overhead in the build output due to the maps code. Also, this does not make the map functional in webgl, so if the map code is being called it could lead to errors.

A better approach to ensure the map code is not compiling into the WebGL build output could be to put the map-related objects into a separate scene, and then exclude that scene for the WebGL build... At least, that's one idea. There may be better ways to go about that, but the gist is to make sure that the maps code is not being referenced by a scene when building WebGL.

natsoragge commented 12 months ago

Thanks for the answer! I was able to get rid of the errors by using the '-s ERROR_ON_UNDEFINED_SYMBOLS=0' argument. For those who might have the same problem:

That solved the issue for me. Creating the ghost WebGL plugin would probably also work, but in my case this solution fitted better.