Trying to catch FMOD errors

Hello,

We are loading sound from assetbundles. All usually works fine, but sometimes (indeed, sometimes), the audio cannot be loaded from the assetbundle, spawning error messages:

Cannot create FMOD::Sound instance for resource archive:

In our code we have a coroutine that looks like this:

while (nextClipToPlay.loadState != AudioDataLoadState.Loaded && nextClipToPlay.loadState != AudioDataLoadState.Failed)
    yield return nextClipToPlay.LoadAudioData();

if (nextClipToPlay.loadState == AudioDataLoadState.Loaded)
{
   audioSource.clip = nextClipToPlay;
   audioSource.Play();      
}

Sometimes it gives me this error on line 2, and when that happens, the loop just continues forever; the loadstate does not change into Failed, thus the coroutine never ends. Spawning error messages each frame.

I have to stress the “sometimes”: on the same device, with the same asset bundles, it mostly works, but sometimes it doesn’t.

Question is twofold:

  • Is there a way to fix this error?
  • But maybe better: is there a good way to catch this error so I can interrupt the loading?

Thanks for any help or insight you can give!
Alex

Edit: this is on Unity 5.4.4p4

Related issue: AudioClip.LoadAudioData returns true but clip remains unloaded - Unity Engine - Unity Discussions