Async/await and webgl builds

Hello,
I’m not sure if this fits to here but im writing anyway:)
I have just started to test new 2017.1 builds to see how goes the new scripting stuff. I have tried to make some async methods which works fine on standalone builds. But when i try to build it using webgl, async methods doesnt seems to continue after awaited task finishes. Is this a known issue or am i making something wrong?

1 Like

It really depends on how to are using async and await. If this involves more than one thread, this won’t work on WebGL, as threads are not supported there. I don’t think that anything on Unity end should use more than one thread. Can you provide more details about the code that is causing the issue?

Here is a code piece that works on standalone players but not on webgl.

using System.Threading.Tasks;
using UnityEngine;

class ExampleAsyncAwait : MonoBehaviour
{
    void Start()
    {
        Task testTask = TestMethod();
    }

    async Task TestMethod()
    {
        Debug.Log("First hello");
        await Task.Delay(1000);

        Debug.Log("Second hello");
        await Task.Delay(1000);

        Debug.Log("Third hello");
        await Task.Delay(1000);

        Debug.Log("Yet another hello");
        await Task.Delay(1000);

        Debug.Log("Finished");
    }
}

Actually it must be no different then coroutines but with nice syntax using the synchronization context provided by unity itself.

I have replaced delays with yields and it seemed to work. It could be possible that those delay tasks are not implemented on webgl.

Yes, that makes sense. Task.Delay is implemented for WebGL, but it uses a System.Timer, which requires threading support: mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs at unity-mono-4.8.0-branch · Unity-Technologies/mono · GitHub

I’m glad you were able to work around the issue.

Thanks for your time. I have just implemented a custom task to make delayed yields. It would be nice if unity provides these by itself like the ones(WaitForSeconds etc…) we use for coroutines.

Anyway i have a second question:) Here is a simple code that shows the problem…

using System.Threading.Tasks;
using UnityEngine;

class ExampleAsyncAwait : MonoBehaviour
{
    void Start()
    {
        Task testTask = TestMethod();
    }

    async Task TestMethod()
    {
        Dummy testObject = await TestSubMethod<Dummy>();
        Debug.Log("This line will not execute");
        Debug.Log(testObject);
    }

    async Task<T> TestSubMethod<T>() where T : class, new()
    {
        T result = new T();
        await TestSubMethod2();
        Debug.Log("This line will be executed");

        return result;
    }

    Task TestSubMethod2()
    {
        Debug.Log("Just a dummy log");
        return Task.FromResult(0);
    }
}

class Dummy
{
    public Dummy()
    {
      
    }
}

This code works fine on standalone players. But at webgl I can’t see the “This line will not execute” comment on console. It seems to be a problem related with generics and async combination. But i’m not sure.

Currently i’m implementing my method with every possible type which i use to avoid this. Any ideas?

Can you provide the full output you get from the standalone and WebGL players? I’m not sure why there is a difference.

Here goes the full logs

Browser Log

index.html:8 Resource interpreted as Stylesheet but transferred with MIME type text/plain: “http://localhost:8080/Immersion.WebGL/TemplateData/style.css”.
UnityLoader.js:234 run() called, but dependencies remain, so not running
printErr @ UnityLoader.js:234
run @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:441278
UnityLoader.da1f3f68d9e4c7fa12541611c3cd53e0 @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:441366
UnityLoader.loadCode.Module @ UnityLoader.js:95
script.onload @ UnityLoader.js:26
blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:444 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help, check https://xhr.spec.whatwg.org/.
read @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:444
loadDynamicLibrary @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:658
(anonymous) @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:1580
(anonymous) @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:1579
callRuntimeCallbacks @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:1325
preRun @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:1354
run @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:441282
runCaller @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:441235
removeRunDependency @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:1570
applyMemoryInitializer @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:441197
useRequest @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:441212
UnityLoader.js:234 pre-main prep time: 9355 ms
printErr @ UnityLoader.js:234
doRun @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:441292
run @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:441307
runCaller @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:441235
removeRunDependency @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:1570
(anonymous) @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:11
doCallback @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:5591
done @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:5602
done @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:4715
storeLocalEntry @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:4633
(anonymous) @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:4726
UnityLoader.da1f3f68d9e4c7fa12541611c3cd53e0.IDBFS.loadRemoteEntry.req.onsuccess @ blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:4652
blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 PlayerConnection initialized from (debug = 0)

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 PlayerConnection disabled - listening mode not supported

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 Initialize engine version: 2017.1.0b6 (38ec4e48ade7)

UnityLoader.js:233 Creating WebGL 2.0 context.
blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 Renderer: WebKit WebGL

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 Vendor: WebKit

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 Version: OpenGL ES 3.0 (WebGL 2.0 (OpenGL ES 3.0 Chromium))

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 GLES: 3

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 EXT_color_buffer_float GL_EXT_color_buffer_float EXT_disjoint_timer_query_webgl2 GL_EXT_disjoint_timer_query_webgl2 EXT_texture_filter_anisotropic GL_EXT_texture_filter_anisotropic OES_texture_float_linear GL_OES_texture_float_linear WEBGL_compressed_texture_s3tc GL_WEBGL_compressed_texture_s3tc WEBGL_debug_renderer_info GL_WEBGL_debug_renderer_info WEBGL_debug_shaders GL_WEBGL_debug_shaders WEBGL_lose_context GL_WEBGL_lose_context

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 OPENGL LOG: Creating OpenGL ES 3.0 graphics device ; Context level <OpenGL ES 3.0> ; Context handle 1

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 UnloadTime: 25.960000 ms

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 Just a dummy log

(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/WebGL/runtime/DebugBindings.gen.cpp Line: 51)

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 This line will be executed

(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/WebGL/runtime/DebugBindings.gen.cpp Line: 51)

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:5584 warning: 2 FS.syncfs operations in flight at once, probably just doing extra work
blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:5584 warning: 2 FS.syncfs operations in flight at once, probably just doing extra work
blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:5584 warning: 2 FS.syncfs operations in flight at once, probably just doing extra work

Standalone Log

Mono path[0] = ‘E:/Develop/Immersion.Binary/Immersion_Data/Managed’
Mono config path = ‘E:/Develop/Immersion.Binary/Immersion_Data/MonoBleedingEdge/etc’
PlayerConnection initialized from E:/Develop/Immersion.Binary/Immersion_Data (debug = 0)
PlayerConnection initialized network socket : 0.0.0.0 55198
Multi-casting “[IP] 192.168.1.247 [Port] 55198 [Flags] 2 [Guid] 3289737884 [EditorId] 1575425679 [Version] 1048832 [Id] WindowsPlayer(KORAY-PC) [Debug] 0” to [225.0.0.222:54997]…
Started listening to [0.0.0.0:55198]
PlayerConnection already initialized - listening to [0.0.0.0:55198]
Player data archive not found at E:/Develop/Immersion.Binary/Immersion_Data/data.unity3d, using local filesystemInitialize engine version: 2017.1.0b6 (38ec4e48ade7)
GfxDevice: creating device client; threaded=1
Direct3D:
Version: Direct3D 11.0 [level 11.1]
Renderer: NVIDIA GeForce GTX 1080 (ID=0x1b80)
Vendor: NVIDIA
VRAM: 8110 MB
Driver: 21.21.13.7892
Begin MonoManager ReloadAssembly
Loading E:\Develop\Immersion.Binary\Immersion_Data\Managed\UnityEngine.dll into Unity Child Domain
Platform assembly: E:\Develop\Immersion.Binary\Immersion_Data\Managed\System.Core.dll (this message is harmless)
Loading E:\Develop\Immersion.Binary\Immersion_Data\Managed\Assembly-CSharp-firstpass.dll into Unity Child Domain
Loading E:\Develop\Immersion.Binary\Immersion_Data\Managed\Assembly-CSharp.dll into Unity Child Domain
Loading E:\Develop\Immersion.Binary\Immersion_Data\Managed\UnityEngine.UI.dll into Unity Child Domain
Loading E:\Develop\Immersion.Binary\Immersion_Data\Managed\UnityEngine.Networking.dll into Unity Child Domain
Loading E:\Develop\Immersion.Binary\Immersion_Data\Managed\UnityEngine.Timeline.dll into Unity Child Domain
Loading E:\Develop\Immersion.Binary\Immersion_Data\Managed\UnityEngine.Analytics.dll into Unity Child Domain
Loading E:\Develop\Immersion.Binary\Immersion_Data\Managed\Newtonsoft.Json.dll into Unity Child Domain
Platform assembly: E:\Develop\Immersion.Binary\Immersion_Data\Managed\System.dll (this message is harmless)

  • Completed reload, in 0.289 seconds
    Initializing input.

XInput1_3.dll not found. Trying XInput9_1_0.dll instead…
Input initialized.

Initialized touch support.

UnloadTime: 0.714602 ms
Just a dummy log
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[ ])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
ExampleAsyncAwait:TestSubMethod2() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:29)
c__async11:MoveNext() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:21) System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:Start(c__async1`1&) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:471)
ExampleAsyncAwait:TestSubMethod()
c__async0:MoveNext() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:13)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(c__async0&) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316)
ExampleAsyncAwait:TestMethod()
ExampleAsyncAwait:Start() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:8)

(Filename: /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs Line: 471)

This line will be executed
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[ ])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
c__async11:MoveNext() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:22) System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:Start(c__async1`1&) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:471)
ExampleAsyncAwait:TestSubMethod()
c__async0:MoveNext() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:13)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(c__async0&) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316)
ExampleAsyncAwait:TestMethod()
ExampleAsyncAwait:Start() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:8)

(Filename: /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs Line: 471)

This line will not execute
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[ ])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
c__async0:MoveNext() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:14)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(c__async0&) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316)
ExampleAsyncAwait:TestMethod()
ExampleAsyncAwait:Start() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:8)

(Filename: /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs Line: 316)

Dummy
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[ ])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
c__async0:MoveNext() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:15)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(c__async0&) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316)
ExampleAsyncAwait:TestMethod()
ExampleAsyncAwait:Start() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:8)

(Filename: /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs Line: 316)

Setting up 4 worker threads for Enlighten.
Thread → id: 4350 → priority: 1
Thread → id: 7aa8 → priority: 1
Thread → id: a71c → priority: 1
Thread → id: 5c58 → priority: 1

Smaller logs if you wish to see;

Browser Log

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 Just a dummy log

(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/WebGL/runtime/DebugBindings.gen.cpp Line: 51)

blob:http://localhost:8080/d8398a8e-4e84-46f6-a460-e7776dcffabb:9301 This line will be executed

(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/WebGL/runtime/DebugBindings.gen.cpp Line: 51)

Standalone Log

Just a dummy log
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[ ])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
ExampleAsyncAwait:TestSubMethod2() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:29)
c__async11:MoveNext() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:21) System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:Start(c__async1`1&) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:471)
ExampleAsyncAwait:TestSubMethod()
c__async0:MoveNext() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:13)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(c__async0&) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316)
ExampleAsyncAwait:TestMethod()
ExampleAsyncAwait:Start() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:8)

(Filename: /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs Line: 471)

This line will be executed
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[ ])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
c__async11:MoveNext() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:22) System.Runtime.CompilerServices.AsyncTaskMethodBuilder1:Start(c__async1`1&) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:471)
ExampleAsyncAwait:TestSubMethod()
c__async0:MoveNext() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:13)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(c__async0&) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316)
ExampleAsyncAwait:TestMethod()
ExampleAsyncAwait:Start() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:8)

(Filename: /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs Line: 471)

This line will not execute
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[ ])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
c__async0:MoveNext() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:14)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(c__async0&) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316)
ExampleAsyncAwait:TestMethod()
ExampleAsyncAwait:Start() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:8)

(Filename: /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs Line: 316)

Dummy
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[ ])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
c__async0:MoveNext() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:15)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(c__async0&) (at /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316)
ExampleAsyncAwait:TestMethod()
ExampleAsyncAwait:Start() (at E:\Develop\Immersion\Immersion.Unity\Assets\Sources\ExampleAsyncAwait.cs:8)

(Filename: /Users/builduser/buildslave/mono/build/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs Line: 316)

Thanks for the details. Indeed, it seems that await TestSubMethod<Dummy>(); never continues. I think this should work in WebGL, so this looks like a bug. Do you mind submitting a bug report with this project? I’d like to take a look at it here.

Posted a bug report using Unity. Case number is 916582.
Thanks for your time :slight_smile:

Thanks, we will investigate this.

Thread necro, but issue was fixed in 2018.1

3 Likes

Unfortunately, this bug has reappeared. Tested in Unity 2019.3.9f1 w/ WASM threading enabled. Opened as case #1243010. The reproduction code is very simple.

 private void Start()
    {
        LogThreadSafe("Start");
      
        Task task1 = Task.Run(() =>
        {
            LogThreadSafe("task1.Run()");
        });

        Task task2 = Task.Run(async () =>
        {
            await Task.Delay(1);
            LogThreadSafe("task2.Run() - Async");
        });

        Task.WhenAll(task1, task2);
      
        LogThreadSafe("Stop");
    }

Gist: https://gist.github.com/stonstad/bf0de9cb7e77096c9600a652a74be3db

4 Likes

I have a separate issue opened w/ Unity regarding ConcurrentDictionary. Switching the above example from ConcurrentQueue to Queue does not change the behavior. Tasks still don’t run.

1 Like

For anyone coming to this I was able to replace all tasks in my project with UniTask and it worked on the WebGL build.

8 Likes

Hi @JoshPeterson

I’m trying to integrate the addressable asset into the WebGL project and facing some serious issues like-

  1. Not able to play audio/video using addressable.
  2. not able to make an asset bundle addressable that was built on another project.
  3. What’s the alternate of AsynOperationHandle while working on WebGL platform.

Sorry, I’m pretty unfamiliar with addressables, so I’m likely not the right person to help here.

@JoshPeterson Is there any sense of urgency around WebGL threading issues? Similarly, my mind is blown that ConcurrentDictionary.Count causes the WebGL player to crash.

2 Likes

I’m unaware of any specific but reports for WebGL related to threading issues, but the WebGL team may have some. I’m not sure what the roadmap is for supporting threads in WebGL using shared array buffers, but again, I’m not directly involved there.

I’d recommend that you submit a bug report about ConcurrentDictionary.Count. Are there any other issues that should be addressed?