Search Unity

Bug? Audio + init log starts after 10-15 seconds

Discussion in 'Web' started by unity3dat, Nov 29, 2018.

  1. unity3dat

    unity3dat

    Joined:
    Aug 9, 2017
    Posts:
    88
    Hi,

    All of the sudden, I experience issues with the audio in my WebGL game in Chrome (Firefox works fine). It only happens in wasm builds (not in asm), and it didn't happen before (I haven't changed anything).
    It just appeared... maybe because Chrome auto updated or something?

    Anyway, I can't find much information about it.
    I checked the logs, and there something weird is happening too.

    This part fires almost immediately (during the loading of my game):

    Code (CSharp):
    1. UnityLoader.js:4 trying binaryen method: native-wasm
    2. UnityLoader.js:4 asynchronously preparing wasm
    3. UnityLoader.js:4 binaryen method succeeded.
    Then, the game is loaded and I can start playing, but there's no audio for 10-15 seconds.
    Then all of the sudden, the audio starts, and together with that, the console continues too:

    Code (CSharp):
    1. Loading player data from data.unity3d
    2. UnityLoader.js:4 Initialize engine version: 2018.2.17f1 (88933597c842)
    3. UnityLoader.js:4 Creating WebGL 2.0 context.
    4. UnityLoader.js:4 Renderer: WebKit WebGL
    5. UnityLoader.js:4 Vendor:   WebKit
    6. UnityLoader.js:4 Version:  OpenGL ES 3.0 (WebGL 2.0 (OpenGL ES 3.0 Chromium))
    7. UnityLoader.js:4 GLES:     3
    8. UnityLoader.js:4  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_compressed_texture_s3tc_srgb GL_WEBGL_compressed_texture_s3tc_srgb WEBGL_debug_renderer_info GL_WEBGL_debug_renderer_info WEBGL_debug_shaders GL_WEBGL_debug_shaders WEBGL_lose_context GL_WEBGL_lose_context
    9. UnityLoader.js:4 OPENGL LOG: Creating OpenGL ES 3.0 graphics device ; Context level  <OpenGL ES 3.0> ; Context handle 1
    10. blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2 The Web Audio autoplay policy will be re-enabled in Chrome 71 (December 2018). Please check that your website is compatible with it. https://goo.gl/7K7WLu
    11. _JS_Sound_Init @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
    12. wasm-function[2809] @ wasm-045f9b1e-2809:34
    13. wasm-function[2777] @ wasm-045f9b1e-2777:886
    14. wasm-function[2668] @ wasm-045f9b1e-2668:304
    15. wasm-function[2656] @ wasm-045f9b1e-2656:17
    16. wasm-function[3802] @ wasm-045f9b1e-3802:82
    17. wasm-function[3797] @ wasm-045f9b1e-3797:346
    18. wasm-function[3793] @ wasm-045f9b1e-3793:78
    19. wasm-function[3792] @ wasm-045f9b1e-3792:13
    20. wasm-function[845] @ wasm-045f9b1e-845:162
    21. wasm-function[8507] @ wasm-045f9b1e-8507:83
    22. wasm-function[8485] @ wasm-045f9b1e-8485:79
    23. wasm-function[8431] @ wasm-045f9b1e-8431:439
    24. wasm-function[8430] @ wasm-045f9b1e-8430:5
    25. (anonymous) @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
    26. callMain @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
    27. doRun @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
    28. run @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
    29. runCaller @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
    30. removeRunDependency @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
    31. processDataJob @ UnityLoader.js:4
    32. a.callback @ UnityLoader.js:3
    33. setTimeout (async)
    34. a.complete @ UnityLoader.js:3
    35. (anonymous) @ UnityLoader.js:4
    36. r.worker.onmessage @ UnityLoader.js:3
    37. UnityLoader.js:4 UnloadTime: 0.700000 ms
    38. [Violation] 'setTimeout' handler took 836ms
    39. 10[Violation] 'requestAnimationFrame' handler took <N>ms
    40. blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2 warning: 2 FS.syncfs operations in flight at once, probably just doing extra work
    41. UnityLoader.js:4 UnloadTime: 8.500000 ms
    42. UnityLoader.js:4 Unloading 5 Unused Serialized files (Serialized files now loaded: 0)
    43. blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2 warning: 2 FS.syncfs operations in flight at once, probably just doing extra work
    44. UnityLoader.js:4
    45. UnityLoader.js:4 Unloading 7 unused Assets to reduce memory usage. Loaded Objects now: 4839.
    46. UnityLoader.js:4 Total: 8.300000 ms (FindLiveObjects: 1.200000 ms CreateObjectMapping: 0.400000 ms MarkObjects: 6.400000 ms  DeleteObjects: 0.300000 ms)
    That didn't happen before. Before, the game loaded and during this load the second part of the console was written, not after 10-15 seconds.

    Does anyone know what's causing this? Is there a fix?

    I stumbled upon this game on the internet: https://webassembly.org/demo/Tanks/
    This game has the exact same issue as I describe, so I guess it's not only a problem in my game...
    (note: the tanks demo has errors in the console, mine hasn't).
    This user seems to address the same problem.

    There's something about Chrome's Web Audio autoplay policy in the logs as you can see... not sure if this has something to do with it.


    Any help is much appreciated... I have no idea how to tackle this...
     
    Last edited: Nov 29, 2018
    trombonaut likes this.
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    What's your Chrome version?
     
  3. unity3dat

    unity3dat

    Joined:
    Aug 9, 2017
    Posts:
    88
    70.0.3538.110 . It happens both on Mac and Windows.
    Tried it with the latest Canary version as well: same problem.
     
  4. lincoln_imagine

    lincoln_imagine

    Joined:
    Nov 30, 2015
    Posts:
    5
    We are experiencing the same issue with Unity 2018.2.10f1 and Web Assembly, but it only happens on certain machines for us even though the Chrome version and settings are the same. We've tried replicating the issue with 2 same model MacBook Pro's with the same settings and one has the problem, and the other doesn't.

    A few other details -
    • We have an HTML login screen that launches into Unity and we only see the problem when launching this way. If we login on our Unity login screen, the issue does not exist.
    • Unity 2017.2.1f1 works
    • We've noticed that the console logs are also frozen for a quite a while after launching the app, and only after the audio plays do we get the backfill of logs.
     
  5. unity3dat

    unity3dat

    Joined:
    Aug 9, 2017
    Posts:
    88
    This indeed seems very similar. I can confirm that we also found devices with the exact same chrome version that doesn't have the issue. But most of our devices have the issue.
     
  6. lincoln_imagine

    lincoln_imagine

    Joined:
    Nov 30, 2015
    Posts:
    5
    I've found that disabling
    WebAssembly baseline compiler
    in Chrome Flags seems to fix the issue on my machine, however switching it to enabled doesn't break the machines that worked all along.
     
  7. unity3dat

    unity3dat

    Joined:
    Aug 9, 2017
    Posts:
    88
    I made an empty build with just an audio file and the problem is still there, so I guess I'll have to wait for a fix... Is this bug known by the Unity devs and on the roadmap to be fixed?
     
  8. lincoln_imagine

    lincoln_imagine

    Joined:
    Nov 30, 2015
    Posts:
    5
  9. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    598
    Are you sure that it's not because of the Autoplay Policy back in google chrome?

    On your test page : https://gsigler.github.io/unitywebassemblybug/
    We have the "AudioContext" warning message in the console and the sound start only when you click on the page.
    If you start your demo and click repeatedly and quickly on the page, the sound start directly.
     
  10. lincoln_imagine

    lincoln_imagine

    Joined:
    Nov 30, 2015
    Posts:
    5
    Yes, that is new with 71 while this issue existed back in 70 and didn't have any AudioContext warnings. We are also able to see that the audio plays faster when we disable the WebAssembly Baseline Compilation. On some machines it's only a second or 2 gain, on other devices like a Chromebook it's a 30 second gain.
     
  11. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    Not sure if this is what you're talking about, but we noticed [some time ago] chrome's audio engine would need some time to "warm up" after the webpage's audiocontext is first actually used. But for us this initial startup delay has been like .5 - 1 seconds, we've never seen anything remotely close to 30 seconds.

    At any rate we worked around the issue by playing a ~.5 second audio clip that is completely silent when the Unity binary first loads.
     
  12. game_apps

    game_apps

    Joined:
    Mar 3, 2016
    Posts:
    36
    ExternEvals are also blocked for the first 10-15 seconds, plus console logs from unity dont appear, in addition to sound issue.

    This happens only on WebAssembly and not in asm.js.
     
  13. lincoln_imagine

    lincoln_imagine

    Joined:
    Nov 30, 2015
    Posts:
    5
    We haven't been able to gain any traction in our bug filed on the V8 issue tracker. Is there a way to push this along with Unity?
     
  14. unity3dat

    unity3dat

    Joined:
    Aug 9, 2017
    Posts:
    88
    Looks like it's assigned now. Let's hope they fix it soon...
     
  15. unity3dat

    unity3dat

    Joined:
    Aug 9, 2017
    Posts:
    88
    @Marco-Trivellato I noticed today that the audio is completely gone in Safari... (also present in Tanks demo) so I'm not sure if this only requires a fix from Chrome. What are your thoughts?
     
  16. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    That’s Safari 12’s new click to play audio policy (older versions will still work). You need to use this workaround atm to fix Safari 12: https://forum.unity.com/threads/chr...io-for-unity-webgl.517758/page-2#post-3988192 (note though this broke Chrome for us so we had to selectively use this code, but perhaps that was just us). Unity’s workaround for Chrome’s policy unfortunately does not work in this case thus we will have to wait for a new version of Unity for a “full fix”.
     
    unity3dat likes this.
  17. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    I saw something similar, when i tried playing a tone as soon as the game starts, but chrome gave error that some gesture must be made by the user before it can play the audio, something like that, seems its a chrome security feature.