Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Bug 1.2.4] [WebGL] Addressable Tasks never complete

Discussion in 'Addressables' started by MaskedMouse, Oct 2, 2019.

  1. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,091
    We've updated addressables from 0.6.8 to 1.2.4 to make use of the .Task property. But to our surprise tasks never finish. I've made a simple setup to demonstrate this in a bug report.
    The await update works
    The normal .completed event handling finishes normally
    but awaiting any addressables API makes it wait indefinitely. When the page is refreshed it will even throw a dependency error. Probably because the task is still awaiting to finish.

    Bug Case: 1188428
     
    Last edited: Oct 2, 2019
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Thanks for the post, we'll look into it.
     
  3. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,091
    I’ve been setting debug logs everywhere in the
    .Task
    property of addressables. But after starting a Task it seems to not debug anything on WebGL. It does in the editor but not on WebGL.
    So I did a sanity check -> started a Task using the
    Task.Factory.StartNew
    api but it fails doing anything as well.
    Then added a regular await with the same task method and that executes just fine.

    So for some reason using the factory method StartNew on webgl doesn’t work?
    I hope this additional information helps a bit

    using Unity 2019.2.8
     
    Last edited: Oct 9, 2019
  4. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    yeah, it feels very helpful. We have this on our current sprint to attack (which means, if we can figure it out, release in 3-4 weeks).

    This added info will be helpful.
     
    MaskedMouse likes this.
  5. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    762
    Hey @MaskedMouse thanks for bringing this to our attention. Unfortunately this is an issue we need to update in our documentation. As it stands System.Threading.* APIs are not supported on WebGL so we won't be able to support using an operations Task property on that platform. As you saw in your testsing, using async and await can work on WebGL but you have to be careful how you use it. Anything that requires more than one thread won't work.

    Hope that helps!
     
    MaskedMouse likes this.
  6. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,091
    Well yeah that explains it as of why it cannot be used. At this point we're using addressables 0.6.8 where the get awaiter pattern is not yet implemented. We simply await the instantiate or load method using an asyncawait plugin from the asset store. After .Task & GetAwaiter pattern has been implemented in addressables it cannot build it anymore due to the plugin and addressables handling the GetAwaiter pattern.
    I̶ ̶g̶u̶e̶s̶s̶ ̶w̶e̶'̶l̶l̶ ̶j̶u̶s̶t̶ ̶h̶a̶v̶e̶ ̶t̶o̶ ̶w̶o̶r̶k̶ ̶a̶r̶o̶u̶n̶d̶ ̶i̶t̶ ̶s̶o̶m̶e̶h̶o̶w̶.̶ I̶'̶v̶e̶ ̶t̶r̶i̶e̶d̶ ̶l̶o̶a̶d̶i̶n̶g̶ ̶t̶h̶e̶ ̶a̶d̶d̶r̶e̶s̶s̶a̶b̶l̶e̶ ̶a̶s̶s̶e̶t̶ ̶i̶n̶ ̶a̶ ̶c̶o̶r̶o̶u̶t̶i̶n̶e̶ ̶b̶u̶t̶ ̶a̶w̶a̶i̶t̶i̶n̶g̶ ̶t̶h̶e̶ ̶c̶o̶r̶o̶u̶t̶i̶n̶e̶ ̶s̶e̶e̶m̶s̶ ̶t̶o̶ ̶n̶o̶t̶ ̶w̶o̶r̶k̶ ̶e̶i̶t̶h̶e̶r̶ ̶d̶u̶e̶ ̶t̶o̶ ̶a̶ ̶d̶e̶p̶e̶n̶d̶e̶n̶c̶y̶ ̶e̶x̶c̶e̶p̶t̶i̶o̶n̶.̶ ̶P̶r̶o̶b̶a̶b̶l̶y̶ ̶t̶h̶e̶ ̶p̶l̶u̶g̶i̶n̶ ̶w̶h̶i̶c̶h̶ ̶c̶a̶n̶n̶o̶t̶ ̶b̶e̶ ̶u̶s̶e̶d̶ ̶a̶t̶ ̶t̶h̶a̶t̶ ̶p̶o̶i̶n̶t̶.̶

    I guess we'll have to find a workaround for loading assets. Maybe even go back to coroutines, even though we pasionately hate them due to their nature of requireing a monobehaviour to actually run & their inability to return a value.
    Have to workaround quite some systems that currently use addressables to be able to update from 0.6.8 to 1.2.4. Fix all their way of loading just because of WebGL. :rolleyes:
    The "It works don't fix it" is not outweighing the update.

    Thanks for looking at the issue!

    edit: Got it working with a workaround using the plugin.
    Hopefully won't have to do this a lot but I can either wrap the asset reference into a coroutine and await that with the plugin. Or await until the IsDone is true. Probably going to wrap it into a coroutine.
    That's going to be quite some work, but I guess it is worth it for the update.
     
    Last edited: Oct 16, 2019
    davidla_unity likes this.
  7. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,091
    @DavidUnity3d It has been a while back since the change has been made in Addressables to disable the Task property in WebGL

    Code (CSharp):
    1. #if UNITY_WEBGL
    2.                 Debug.LogError("Multithreaded operation are not supported on WebGL.  Unable to aquire Task.");
    3.                 return default;
    4. #else
    Multi-threading and WebGL has always been on hold due to Spectre and SharedArrayBuffer being disabled in browsers by default. However, Chrome & Firefox have re-enabled SAB. Safari has not yet enabled it by default.
    Is there something that could be done in Addressables to re-enable the Task property for WebGL for atleast Chrome and Firefox?

    https://caniuse.com/#feat=sharedarraybuffer
     
  8. psynusoidal

    psynusoidal

    Joined:
    May 26, 2015
    Posts:
    14
  9. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,091
    I wasn't looking for a workaround. I was just bringing it to the attention again.
    The last version of 2019.4 included a bug fix for WebGL threading support.
    WebGL: IL2CPP was not generating threading-enabled code when the threadsSupport project setting was set. (1243010)
    Also Firefox just re-enabled SAB again so it is worth looking into again. I hope it will be re-enabled on Safari as well. Edge now runs on chromium so basically the main browsers except Safari should have SAB enabled again.

    As for the workaround I use an async await plugin. I'm simply waiting until the IsDone property is true instead of awaiting the Task.
     
  10. psynusoidal

    psynusoidal

    Joined:
    May 26, 2015
    Posts:
    14
    HexiledGames likes this.