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

WebGL runtime error audio listener

Discussion in 'Web' started by Modernllama, Feb 2, 2017.

  1. Modernllama

    Modernllama

    Joined:
    Nov 30, 2012
    Posts:
    19
    Hi,

    When attempting to run a level of my game, I get this error with the stack trace below:

    Code (CSharp):
    1. exception thrown: TypeError: Argument 1 of AudioListener.setPosition is not a finite floating-point value.,_JS_Sound_SetListenerPosition@blob:http://localhost:61867/1621702e-ea16-994c-b122-e425a39ff6d7:7562:2
    2. __ZN4FMOD6System23set3DListenerAttributesEiPK11FMOD_VECTORS3_S3_S3_@blob:http://localhost:61867/1bff9c54-239c-ca4b-af53-21b8b27a3900:1156383:1
    3. __ZN13AudioListener8DoUpdateEv@blob:http://localhost:61867/1bff9c54-239c-ca4b-af53-21b8b27a3900:781601:1
    4. __ZN13AudioListener6UpdateEv@blob:http://localhost:61867/1bff9c54-239c-ca4b-af53-21b8b27a3900:1417898:1
    5. __ZN12AudioManager6UpdateEv@blob:http://localhost:61867/1bff9c54-239c-ca4b-af53-21b8b27a3900:933587:1
    6. __ZN11AudioModule6UpdateEv@blob:http://localhost:61867/1bff9c54-239c-ca4b-af53-21b8b27a3900:1626463:1
    7. __ZZL31InitializeAudioManagerCallbacksvEN31PostLateUpdateUpdateAudiostruct7ForwardEv@blob:http://localhost:61867/1bff9c54-239c-ca4b-af53-21b8b27a3900:1622262:1
    8. __Z10PlayerLoopv@blob:http://localhost:61867/1bff9c54-239c-ca4b-af53-21b8b27a3900:478615:1
    9. __ZL8MainLoopv@blob:http://localhost:61867/1bff9c54-239c-ca4b-af53-21b8b27a3900:1168425:1
    10. dynCall_v@blob:http://localhost:61867/1bff9c54-239c-ca4b-af53-21b8b27a3900:1680458:1
    11. Runtime.dynCall@blob:http://localhost:61867/1621702e-ea16-994c-b122-e425a39ff6d7:299:11
    12. _emscripten_set_main_loop/browserIterationFunc@blob:http://localhost:61867/1621702e-ea16-994c-b122-e425a39ff6d7:1975:4
    13. Browser.mainLoop.runIter@blob:http://localhost:61867/1621702e-ea16-994c-b122-e425a39ff6d7:2077:5
    14. Browser_mainLoop_runner@blob:http://localhost:61867/1621702e-ea16-994c-b122-e425a39ff6d7:2013:3
    15. UnityErrorHandler@http://localhost:61867/Release/UnityLoader.js:1:1754
    16. window.onerror@http://localhost:61867/Release/UnityLoader.js:2:301
    This only occurs at runtime. Any thoughts as to why this might be a problem?

    Thanks,
     
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Is this browser-specific? which Unity version?
     
  3. Charles-Van-Norman

    Charles-Van-Norman

    Joined:
    Aug 10, 2010
    Posts:
    86
    I also have this issue. Seems to happen randomly. Building with 5.5.0f3 and running on latest Chrome.
     
  4. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    236
    I also had/have this issue. Haven't seen it in a while but definitely something that was under 5.5.0f3.
    Both under Chrome and FF.

    We're now on 5.6 but I can't yet tell if it is still in this one.
     
  5. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    If anyone can reproduce the issue please submit a bug report.
     
  6. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    236
    I would love to ;)

    It only happens in actual WebGL content, never in the editor. Furthermore, there is nothing that hints on it being consistently reproducible.

    In our last project (multiplayer) the only thing I could think of is a moment where an object (triggering a 3d sfx) has been placed outside of float range. Its a (very) long shot - but one nonetheless.

    EDIT: I might be able to give this another shot in our next project later today...
     
  7. amateurd

    amateurd

    Joined:
    Nov 1, 2016
    Posts:
    97
    Happens on Firefox, 2017.2, not always.
     
  8. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    I am having this error in firefox unity 2019.4f when trying to use a keydown to set a javascript variable value to -30 but it does not fail on -10? I am not working with any sound files.
     
  9. Nolex

    Nolex

    Joined:
    Dec 10, 2010
    Posts:
    115
    I found similar bug with AudioSource.Pause() in Unity 2019.4.37f (WebGL).

    If I call Play() or UnPause() after Pause(), then the game crashes with error:
    Uncaught TypeError: Failed to execute 'start' on 'AudioBufferSourceNode': The provided double value is non-finite.

    My fix for WebGL:

    Code (CSharp):
    1.     float lastSourceTime = 0;
    2.  
    3.     void PauseMusic(AudioSource source)
    4.     {
    5. #if UNITY_WEBGL
    6.             lastSourceTime = source.time;
    7.             source.Stop();
    8. #else
    9.             source.Pause();
    10. #endif
    11.     }
    12.  
    13.     void PlayMusic(AudioSource source)
    14.     {
    15. #if UNITY_WEBGL
    16.             if (lastSourceTime > 0)
    17.             {
    18.                 source.time = lastSourceTime;
    19.                 lastSourceTime = 0;
    20.             }
    21. #endif
    22.  
    23.             source.Play();
    24.         }
    25.     }
    Maybe someone will help. :)

    P.S. Unity 2019.2.12 doesn't have this bug.
     
  10. hallonavi

    hallonavi

    Joined:
    Aug 24, 2022
    Posts:
    1
    Thank you so much! I was having the same problem but different scenario. I'm switching audio clips to a single audiosource, and adding `audiosource.time = 0` just before playing the new audioclip, solved the issue in WebGL.

    Update:
    Setting time to zero didn't work. I found out the cause, and this has to be an Unity bug... I think.

    When you build webgl, either in development build or not, (it is easier in development build), go to Build\webgl-output.framework.js.gz, decompress it and modify build.framework.js.


    Add the following line (see comment). Save the Js, and compress it again. I don't know what does startOffset do but, at least, it plays audios just fine.

    Code (JavaScript):
    1. channel.playSoundClip = function(soundClip, startTime, startOffset) {
    2.   try {
    3.    var self = this;
    4.    this.source = soundClip.createSourceNode();
    5.    this.setupPanning();
    6.    this.source.onended = function() {
    7.     self.disconnectSource();
    8.     if (self.callback) {
    9.      dynCall("vi", self.callback, [ self.userData ]);
    10.     }
    11.    };
    12.    this.source.loop = this.loop;
    13.    this.source.loopStart = this.loopStart;
    14.    this.source.loopEnd = this.loopEnd;
    15.    // ADD THIS LINE BEFORE start function call
    16.    if(isNaN(startOffset)){startOffset = 0;}
    17.    this.source.start(startTime, startOffset);
    18.    this.source.scheduledStartTime = startTime;
    19.    this.source.playbackStartTime = startTime - startOffset / this.source.playbackRate.value;
    20.    this.source.setPitch(this.pitch);
    21.   } catch (e) {
    22.    console.error("Channel.playSoundClip error. Exception: " + e);
    23.   }
     
    Last edited: Oct 3, 2022
  11. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
    Still a problem in unity 2022 randomly appears in firefox running webgl
     
  12. borisenkioleg

    borisenkioleg

    Joined:
    Feb 14, 2016
    Posts:
    2
    Same problem with aousio clip loaded from StreaminAssets
    Unity 2021.3.11f
     
  13. osklau

    osklau

    Joined:
    Nov 14, 2022
    Posts:
    1
    This bug has been haunting my product since the summer. Currently on 2021.3.9, but switching to 2021.3.15 didn't eliminate it. Any chance of a fix from Unity soon? Messing with timings and audio source management can fix some cases, but it always seems to pop up somewhere else.
     
  14. legoesbenr

    legoesbenr

    Joined:
    Apr 27, 2022
    Posts:
    10
    A little late to the game but I had the same problem. After initiating an audiosource and started .Play(). After the parent of the audiosource is destroyed and then a new instance of ausiosource is instantiated I get glitchy sound and some times one or more audiosources fail with this error and don't play.

    I implemented OnDestroy(){} on the parent object of the audiosource and made sure to calle audioSource.Stop(); when destroying the parent. Then the new audiosources spun up after works fine.
     
    VirtualMaestro likes this.
  15. VirtualMaestro

    VirtualMaestro

    Joined:
    Jul 2, 2014
    Posts:
    21
    Was there any bug report created on this issue?
     
  16. unity_17412D978020B89D2E5E

    unity_17412D978020B89D2E5E

    Joined:
    Oct 21, 2022
    Posts:
    3
     
  17. unity_17412D978020B89D2E5E

    unity_17412D978020B89D2E5E

    Joined:
    Oct 21, 2022
    Posts:
    3

    can you tell me how did you compressed back to .unityweb file
     
  18. akig2016

    akig2016

    Joined:
    May 10, 2020
    Posts:
    3
    I have found a permanent solution for this. It uses @hallonavi solution. Instead of altering after building, alter the source code.
    1. Find Audio.js file "Unity/Hub/Editor/2021.3.19f1/PlaybackEngines/WebGLSupport/BuildTools/lib/Audio.js"
    2. Search for function "channel.playSoundClip = function (soundClip, startTime, startOffset)"
    3. Add the following as shown in pic Screenshot 2023-03-02 at 2.46.55 PM.png

    if(isNaN(startTime)){startTime = 0;}
    if(isNaN(startOffset)){startOffset = 0;}
    Note: you need to do for the unity version you are working on.
    Hope it helped. :)
     
    Flyingcap, ig_j, Faikus and 2 others like this.
  19. akig2016

    akig2016

    Joined:
    May 10, 2020
    Posts:
    3
    you can check my solution. It solves the issue
     
  20. haythamnikolaidis

    haythamnikolaidis

    Joined:
    Apr 22, 2019
    Posts:
    1
    @akig2016 You are a true hero. Thank you! Your input has saved me from a weeks worth of torment. Your solution resolved this issue for me in 2021.3.5f1
     
    vorlds_admin likes this.
  21. nnhhaadd

    nnhhaadd

    Joined:
    Sep 7, 2015
    Posts:
    11
    Do we have any update from Unity on this issue? @akig2016 solution works great, but I think we need an answer from Unity. From my experience, by forcing NaN to 0, I can play the audio source, but that means no offset = no Pause and UnPause.
     
  22. MarcelPursche

    MarcelPursche

    Unity Technologies

    Joined:
    Mar 3, 2021
    Posts:
    45
    Hi,
    Normally, there shouldn't be any NaN values ending up in the startTime or startOffset parameters. So while this workaround works I am interested in finding the root cause of this.
    Can you tell me how you are able to reproduce this bug and on which Unity version?
    Also what "Load Type" is set for the audio clips, "Compressed In Memory" or "Decompress On Load"?
    I tried this to switch the audio clip of a paused audio source but I was not able to reproduce the error:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Audio;
    5.  
    6. public class SwitchAudioSourceBehaviour : MonoBehaviour
    7. {
    8.     public AudioSource audioSource;
    9.     public AudioClip firstAudioClip;
    10.     public AudioClip secondAudioClip;
    11.    
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         StartCoroutine(SwitchAudioSource());
    16.     }
    17.  
    18.     IEnumerator SwitchAudioSource()
    19.     {
    20.         audioSource.clip = firstAudioClip;
    21.         audioSource.Play();
    22.  
    23.         yield return new WaitForSeconds(0.5f);
    24.  
    25.         audioSource.Pause();
    26.  
    27.         yield return new WaitForSeconds(0.5f);
    28.  
    29.         audioSource.clip = secondAudioClip;
    30.         audioSource.Play();
    31.     }
    32. }
    I was not able to reproduce any "non-finite floating point" errors or distortion in audio playback on Unity 2023.2.0a8, 2022.2.13f1 and 2021.3.22f1.
     
  23. nnhhaadd

    nnhhaadd

    Joined:
    Sep 7, 2015
    Posts:
    11
    I'm using Unity 2023.1.0a13. It happens when I try to download and play an mp3 file using
    UnityWebRequestMultimedia.GetAudioClip
    . Not sure if that is uncompressed or compressed. I guess it depends on the length of the clip? The first play works fine, but when I try to call play again that error shows up in the console. I'll try to create a producible project later.
     
    MarcelPursche likes this.
  24. nnhhaadd

    nnhhaadd

    Joined:
    Sep 7, 2015
    Posts:
    11
    Hi @MarcelPursche. This is awkward, I wasn't able to create a Unity producible project for you. Somehow everything works as expected without the NaN check guard. But here is a build that exhibits that bug. Just load it up fill in the path to the mp3 file and hit play a few times. You will see that error in the console.
    bug-audio-nan.PNG
    If I remember correctly, all I did was just download the mp3 file then assign it to the AudioSource and play. Unfortunately, this test project was lost.
     

    Attached Files:

  25. MarcelPursche

    MarcelPursche

    Unity Technologies

    Joined:
    Mar 3, 2021
    Posts:
    45
    Hi @nnhhaadd ,
    Thanks, I was able to reproduce the bug now. The error only occurs if the AudioSource.loop is set to true and the audio clip is an mp3 loaded via a WebRequest. So as a workaround it is also possible to disable looping audio if it is not needed.
     
  26. nnhhaadd

    nnhhaadd

    Joined:
    Sep 7, 2015
    Posts:
    11
    That's great, but I mean looping is kinda a fundamental feature right? If I want to download and play a BGM for example. Do you guys plan to fix this in a future release? If so which version can I expect this to be fixed?
     
  27. MarcelPursche

    MarcelPursche

    Unity Technologies

    Joined:
    Mar 3, 2021
    Posts:
    45
    Hi @nnhhaad,
    Sorry, I forgot to mention that. Yes, I created a bug ticket and brought up the bug with the team. I can't give you a timeframe right now but I will post an update in this thread.
     
    LukeImmersive and nnhhaadd like this.
  28. VirtualMaestro

    VirtualMaestro

    Joined:
    Jul 2, 2014
    Posts:
    21
  29. legoesbenr

    legoesbenr

    Joined:
    Apr 27, 2022
    Posts:
    10

    This is awesome except for us using Unity build Cloud...
    @MarcelPursche can we get this hack to the build cloud until you have figured this out?
    And please patch all LTS-versions.
     
  30. legoesbenr

    legoesbenr

    Joined:
    Apr 27, 2022
    Posts:
    10
    Just FYI, tried converting all our files to .ogg and same issue. So it's not tied to the .mp3 format.
     
  31. legoesbenr

    legoesbenr

    Joined:
    Apr 27, 2022
    Posts:
    10
    Just wanted to pitch in with our workaround until this gets resolved.

    We disabled looping the audio source and instead implemented an audio source wrapper, that manually restarts the audiosource once playback is completed. This solved the problem.

    This was discovered in 2017 and confirmed back in April. It's a shame it hasn't already been fixed.
     
  32. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    A fix to this issue landed 28 days ago to our trunk branch. The issue tracker writes "RESOLUTION NOTE (FIX VERSION 2023.3.0A2)". I see that backports to 2021.3, 2022.3, 2023.1 and 2023.2 are currently under review.
     
  33. dan_soqqle

    dan_soqqle

    Joined:
    Feb 2, 2022
    Posts:
    114
    having this issue, but i do not have loop on. I restarted the scene via loadSceneAsync (Addressables) and the Audio that was previously playing on a gameObject, stopped playing with this error.
     
  34. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Gotcha, that does read like some other issue. A bug report on that case specifically would be welcome.