Search Unity

Bug Cant build Unity WebGL when PlayerSettings.WebGL.threadsSupport is true

Discussion in 'Web' started by DrViJ, Aug 16, 2020.

  1. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    161
    Hi everyone! I was experimenting with UniTasks and wanted to try to use UniTask.Run().
    But UniTask.Run() crashes without any exception in WebGL. So I tried to enable WebGLThreadsSupport.
    But now I have an issue when trying to build WebGL in 2020.1.2f1.

    Everything builds if I use WebGLThreadsSupport: 0
    I get error if I use WebGLThreadsSupport: 1

    The error is:
    Failed running "C:/Program Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe" -E "C:/Program Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\Emscripten\emcc" @"C:\WorkProjects\DrViJ\PerfectCut\Assets\..\Temp\emcc_arguments.resp"

    Maybe somebody can tell what can be the reason of such error?

    Does threadsSupport is not allowed anymore?

    emcc_arguments.resp file is:

    Code (CSharp):
    1.  
    2.  -O3 -g0 -DUNITY_WEBGL=1 -s PRECISE_F32=2 -s USE_WEBGL2=1 -s FULL_ES3=1 -s
    3.  "EXTRA_EXPORTED_RUNTIME_METHODS=['addRunDependency','removeRunDependency','FS_createPath','FS_createDataFile','ccall','cwrap','stackTrace']" -s
    4.  DISABLE_EXCEPTION_CATCHING=0 -s TOTAL_MEMORY=16777216 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=8 -s PTHREAD_HINT_NUM_CORES=4 -s PROXY_TO_PTHREAD=0 -s TEXTDECODER=0 -s
    5.  PROXY_TO_PTHREAD=0 -s WASM=1 -s "BINARYEN_TRAP_MODE='allow'" -s ALLOW_MEMORY_GROWTH=1 -s WASM_MEM_MAX=16777216 -s MODULARIZE=1 -s EXPORT_NAME=unityFramework
    6.  --memory-init-file 1 --emit-symbol-map --output_eol linux  -o
    7.  "C:\WorkProjects\DrViJ\PerfectCut\Temp\StagingArea\Data\linkresult_wasm\build.js" --pre-js "C:/Program Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\prejs\Error.js"
    8.  --pre-js "C:/Program Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\prejs\FileSystem.js" --pre-js "C:/Program
    9. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\prejs\FullScreen.js" --pre-js "C:/Program
    10. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\prejs\MediaDevices.js" --pre-js "C:/Program
    11. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\prejs\SendMessage.js" --js-library "C:/Program
    12. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\lib\Audio.js" --js-library "C:/Program
    13. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\lib\Cursor.js" --js-library "C:/Program
    14. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\lib\Eval.js" --js-library "C:/Program
    15. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\lib\FileSystem.js" --js-library "C:/Program
    16. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\lib\Logging.js" --js-library "C:/Program
    17. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\lib\Profiler.js" --js-library "C:/Program
    18. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\lib\SystemInfo.js" --js-library "C:/Program
    19. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\lib\UnetWebSocket.js" --js-library "C:/Program
    20. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\lib\Video.js" --js-library "C:/Program
    21. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\lib\WebCam.js" --js-library "C:/Program
    22. Files/Unity/Hub/Editor/2020.1.2f1/Editor/Data/PlaybackEngines/WebGLSupport\BuildTools\lib\WebRequest.js" "C:\WorkProjects\DrViJ\PerfectCut\Temp\StagingArea\Data\Native\build.bc"
    23.  
    24.  
     
  2. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    161
    Снимок.PNG
     
    deus0 likes this.
  3. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    161
    The bug was reported, case 1270915, successfully reproduced with Unity QA team
     
    deus0 likes this.
  4. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    I can repro with 2020.1.2. Thanks for the heads up!
     
    deus0 and DrViJ like this.
  5. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    Reproduced in 2020.1.4f1.
     
    DrViJ likes this.
  6. Davit87

    Davit87

    Joined:
    Mar 18, 2018
    Posts:
    6
    Reproduced in 2020.1.5f1
     
  7. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    Reproduced in 2020.1.6f1.
     
  8. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    Reproduced in 2020.1.7f1.

     
  9. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    This is an unfortunate regression that stems from an internal LLVM compiler error after Unity multithreaded file IO codebase updated its use of atomics some time ago. We are working on patching up the whole compiler toolchain to a newer version. I believe the latest Unity version where the issue is not present will be the 2019.4 release branch.
     
    DrViJ likes this.
  10. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    @jukka_j Thank you for the update. It is much appreciated.

    2020.1.0f is the latest version of Unity which works with WebGL threading enabled.

    The challenge our team is facing is that 2020.1.0f was an initial release. The inability to create these builds in WebGL is a serious roadblock. There have been many subsequent releases with critical fixes since 2020.1.0f initially debuted.

    Not wanting to complain, but also communicating that this is a major pain point for us. I think the official answer is "WebGL threading is unsupported". That isn't a great answer because this was a feature that was communicated and highly publicized to the world over two years ago. This is very much a hardship. Right now, we have a shippable product that is waiting on Unity to follow-through with their commitments.
     
    ashwani_mpllc, xucian and DrViJ like this.
  11. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Heard and understood - we are working on resolving these issues the best that we can.
     
  12. ercindedeoglu

    ercindedeoglu

    Joined:
    Aug 9, 2015
    Posts:
    3
    Reproduced in 2021.1.1f1
     
  13. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,166
    2022.1.0b9

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6. public static class Initial
    7. {
    8.     [InitializeOnLoadMethod]
    9.     public static void Init()
    10.     {
    11.         PlayerSettings.WebGL.threadsSupport = true;
    12.     }
    13. }
    14.  
    Code (CSharp):
    1. Internal build system error. BuildProgram exited with code -2147024809.
    2. System.ArgumentException: You're trying to copy to webgl/Build/webgl.framework.js more than once. Previously from Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.framework.js and now from Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.worker.framework.js
    3.   at Bee.Core.CopyTool.Setup(NPath target, NPath from)
    4.   at WebGLPlayerBuildProgram.WebGLPlayer.SetupCompression(NPath input, NPath output)
    5.   at WebGLPlayerBuildProgram.WebGLPlayer.SetupPostProcessBuildFile(NPath path)
    6.   at WebGLPlayerBuildProgram.WebGLPlayer.SetupPlayerExecutable()+MoveNext()
    7.   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
    8.   at System.Collections.Generic.SparseArrayBuilder`1.ReserveOrAdd(IEnumerable`1 items)
    9.   at System.Linq.Enumerable.ConcatNIterator`1.LazyToArray()
    10.   at System.Linq.Enumerable.ConcatNIterator`1.ToArray()
    11.   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
    12.   at PlayerBuildProgramLibrary.PlayerBuildProgramBase.RunBuildProgram()
    13.   at PlayerBuildProgramTypeWrapper.Run(String[] args)
    14.   at Program.Main(String[] args)
    15. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
     
  14. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    846
    What's the current state of this issue? @jukka_j @anthony_b_
    It's already been 2 years since @stonstad reported it as an important blocker for his project.
    I find this quite disturbing
     
  15. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    I cancelled the WebGL version of the product and released to PC, iOS, and Android. WebGL would have been awesome, though.

    Unity's blog communicated that threading for WebGL was forthcoming and they did add an experimental version in 2019.1 (https://forum.unity.com/threads/multithreading-and-webgl.817986/). A fully supported version never materialized and the team appears to be slow-playing things. I have not seen any recent updates from them, re: C# threading support and my question here and in another forum is unanswered.

    I anticipate that this capability is blocked or will be replaced by the planned switch to .NET Core.
     
    DrViJ likes this.
  16. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    846
    I imagine writing native javascript workers could be acceptable in some cases, but ofc, you'd just have to duplicate that logic. Might be worth it if there are just logs of calculations going on (I'm even imagining modelling the params and instructions of those calculations into a common type - basically a string which then you can parse on both C# and js, so that you can at least reduce some duplication).
    However, and this might be the case for some people, I only needed support for async/await via the UniTask plugin, and this plugin allowed me to do that without webgl threading (it's basically all done on the main thread, scheduled via the regular Update)