WebGL build fails in Unity 2022

#207 · closed · 2 comments

View on GitHub ↗

natsoragge

**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](https://github.com/microsoft/MapsSDK-Unity/assets/16673871/26ea5922-9483-45cb-9bdb-0a01d1c6ef72) **Environment (please complete the following information):** - Unity version: [e.g. 2022.3.6f1] - Maps SDK Package version: [e.g. 0.11.2] **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

Comments

kircher1

I can offer a quick workaround, which will stub out those functions in the WebGL build so that the build will not fail. * First locate this `MicrosoftGeospatialDecompressionStubs.cpp` file in the package: ![image](https://github.com/microsoft/MapsSDK-Unity/assets/20366429/6f755e44-15f0-4e58-bee9-b703fe69c519) * Copy that file into your project, under a folder like 'WebGL'. * After you copy the file, restrict it's platform to WebGL: ![image](https://github.com/microsoft/MapsSDK-Unity/assets/20366429/867c5719-78b6-4fce-aa76-dd8f0f5251bc) 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

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: - Go to ProjectSettings folder and open ProjectSettings.asset - Search for webGLEmscriptenArgs - Add the argument in front of it, like `webGLEmscriptenArgs: -s ERROR_ON_UNDEFINED_SYMBOLS=0` That solved the issue for me. Creating the ghost WebGL plugin would probably also work, but in my case this solution fitted better.