Search Unity

Bug in AudioListener: AL_Invalid_Value

Discussion in 'iOS and tvOS' started by The-Scripter, Jun 29, 2010.

  1. The-Scripter

    The-Scripter

    Joined:
    Nov 10, 2009
    Posts:
    30
    I think I have found a bug in the AudioListener that gives an error when I use the pause function. I will prepare a bug report and hope it is fixed in the next version, but before then I was hoping someone might have encountered it or be able to suggest a workaround.

    The error happens consistently on the iPhone and occasionally in the Editor, when I use AudioListener.pause. In the editor I receive the error: AL_Invalid_Value, sometimes specifying an AudioSource. This code produces it sometimes:
    Code (csharp):
    1. function PauseGame(){
    2.         AudioListener.pause = true;
    3.         savedTimeScale = Time.timeScale; //Save timescale to be restored later
    4.         Time.timeScale = 0;
    5.         ...
    6. }
    7.  
    and in this code it happens when I move from the main scene to another scene if a sound was playing before pausing:
    Code (csharp):
    1. function OnLevelWasLoaded(){
    2.     Time.timeScale = 1;
    3.     AudioListener.pause = false;
    4.     enabled=false;
    5. }
    6.  
    I know it is the AudioListener causing the problem because if I comment out those lines the crashes stop, and when no sound files were present there were also no crashes.

    I have tried making sure the AudioListener is always unpaused before changing scenes, or changing the timescale, but that did not help. There is always 1 Listener in the scene. Does this make sense to anyone?
     
  2. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,272
    I have just hit that issue with unity iphone 1.7 after trying to implement a mute button with AudioListener.pause

    Not fixed then I guess...

    says Assert in file: ... /Runtime/Audio/AudioManager.cpp at line: 346

    Edit: The workaround is AudioListener.volume = 0/1
     
  3. 3dgrinder

    3dgrinder

    Joined:
    Oct 21, 2008
    Posts:
    249
    I faced it at Unity 1.7 randomly not consistently.
     
  4. The-Scripter

    The-Scripter

    Joined:
    Nov 10, 2009
    Posts:
    30
    I got around this by avoiding the AudioListener.pause function. You could set the volume to 0, but I was using the function to pause the game, and there was a specific object where I wanted the sound to be properly paused so it would start off from the same place when the game was resumed. So inside PauseGame() I added code to find this object (slightly messy but it works) and pause the AudioSource on that GameObject, then set volume to 0 to simply mute all other sounds. It was great to see the random crashes finally stop!

    You could also try pausing all AudioSources using FindObjectsOfType(AudioSource), or another way that wouldn't be so slow.
     
    Last edited: Sep 27, 2010