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

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):

UnityLoader.js:4 trying binaryen method: native-wasm
UnityLoader.js:4 asynchronously preparing wasm
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:

Loading player data from data.unity3d
UnityLoader.js:4 Initialize engine version: 2018.2.17f1 (88933597c842)
UnityLoader.js:4 Creating WebGL 2.0 context.
UnityLoader.js:4 Renderer: WebKit WebGL
UnityLoader.js:4 Vendor:   WebKit
UnityLoader.js:4 Version:  OpenGL ES 3.0 (WebGL 2.0 (OpenGL ES 3.0 Chromium))
UnityLoader.js:4 GLES:     3
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
UnityLoader.js:4 OPENGL LOG: Creating OpenGL ES 3.0 graphics device ; Context level  <OpenGL ES 3.0> ; Context handle 1
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
_JS_Sound_Init @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
wasm-function[2809] @ wasm-045f9b1e-2809:34
wasm-function[2777] @ wasm-045f9b1e-2777:886
wasm-function[2668] @ wasm-045f9b1e-2668:304
wasm-function[2656] @ wasm-045f9b1e-2656:17
wasm-function[3802] @ wasm-045f9b1e-3802:82
wasm-function[3797] @ wasm-045f9b1e-3797:346
wasm-function[3793] @ wasm-045f9b1e-3793:78
wasm-function[3792] @ wasm-045f9b1e-3792:13
wasm-function[845] @ wasm-045f9b1e-845:162
wasm-function[8507] @ wasm-045f9b1e-8507:83
wasm-function[8485] @ wasm-045f9b1e-8485:79
wasm-function[8431] @ wasm-045f9b1e-8431:439
wasm-function[8430] @ wasm-045f9b1e-8430:5
(anonymous) @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
callMain @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
doRun @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
run @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
runCaller @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
removeRunDependency @ blob:https://www.mysite.com/920f163c-0f8e-46f5-bdee-3ff53f1e7f85:2
processDataJob @ UnityLoader.js:4
a.callback @ UnityLoader.js:3
setTimeout (async)
a.complete @ UnityLoader.js:3
(anonymous) @ UnityLoader.js:4
r.worker.onmessage @ UnityLoader.js:3
UnityLoader.js:4 UnloadTime: 0.700000 ms
[Violation] 'setTimeout' handler took 836ms
10[Violation] 'requestAnimationFrame' handler took <N>ms
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
UnityLoader.js:4 UnloadTime: 8.500000 ms
UnityLoader.js:4 Unloading 5 Unused Serialized files (Serialized files now loaded: 0)
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
UnityLoader.js:4
UnityLoader.js:4 Unloading 7 unused Assets to reduce memory usage. Loaded Objects now: 4839.
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]( Chrome On The Dev Branch (version 66) May Block Audio For Unity WebGL page-2#post-3938836) 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…

1 Like

What’s your Chrome version?

70.0.3538.110 . It happens both on Mac and Windows.
Tried it with the latest Canary version as well: same problem.

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.

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.

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.

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?

We have filed a bug with V8, which we believe is causing the issue. You can track it (and star it) here: 8549 - v8 - V8 JavaScript Engine - Monorail

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.

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.

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.

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.

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?

Looks like it’s assigned now. Let’s hope they fix it soon…

@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?

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: Chrome On The Dev Branch (version 66) May Block Audio For Unity WebGL 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”.

1 Like

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.