Ran into a rather unfortunate, but devastating problem that I’m hoping someone can shed some light on–tried asking on the main Unity forums, but it’s all crickets there. The main gist is as such: We have two main scenes and a loading scene. Whenever the player transitions to the next scene, we move them into a loading scene while the next scene asynchronously loads–pretty standard stuff, right?
In order to have music continue playing all the while, the AudioSource component is attached to our GameManager object, which is marked as DontDisableOnLoad (or whatever it’s called), thus it persists between all scenes. However, every 1 in 100 or so transitions, Unity inexplicably crashes–interestingly, the actual AudioSource’s clip is NEVER changed during this time–it always plays the same song on a loop. However, as we don’t use a persistent camera (the camera belongs to each loaded scene, including the loading screen itself), the AudioListener changes each time a transition is encountered. Also, the Audiosource’s clip is set to loop.
Even more interesting is that it never crashes on the LoadingScreen itself–it’s always one of the two ‘main game’ scenes that seems to crash before being fully loaded. As you can imagine, this is an incredibly frustrating bug that seems to have no obvious cause–I can confirm though, however, that it does not happen when the loading screen is not used. Let me repeat: when LoadLevelAsync is not called/used, there is never a crash. Frustratingly, it also never happens during Debug mode. I know this because I set up a test to force the player character to repeatedly move between the scenes. This runs over night and crashes, without fail, within 100 iterations or so, but when asynchronous scene loading isn’t used/Debug Mode is enabled, it’s still running in the morning, after some 20k iterations.
Again, I’d love to provide a repro project, but it’d be incredibly difficult at this point, given the maturity and complexity of our project. Mainly just posting this to see if anyone can throw out any leads. With debug symbols enabled, this is the stack trace I get when it crashes:
========== OUTPUTING STACK TRACE ==================
0x00007FFB7E729B71 (UnityPlayer) FMOD::Codec::read
0x00007FFB7E7226A3 (UnityPlayer) FMOD::CodecFSB5::readInternal
0x00007FFB7E729B71 (UnityPlayer) FMOD::Codec::read
0x00007FFB7E6DCCC5 (UnityPlayer) FMOD::SoundI::readData
0x00007FFB7E6DB6F1 (UnityPlayer) FMOD::SoundI::read
0x00007FFB7E6C80AE (UnityPlayer) FMOD::SystemI::createSoundInternal
0x00007FFB7E6C9301 (UnityPlayer) FMOD::SystemI::createSound
0x00007FFB7E6B3783 (UnityPlayer) FMOD::System::createSound
0x00007FFB7E0E3677 (UnityPlayer) LoadFMODSound
0x00007FFB7E0B57C9 (UnityPlayer) AudioClip::AwakeFromLoadThreaded
0x00007FFB7DD734F6 (UnityPlayer) PersistentManager::postReadActivationQueue
0x00007FFB7DD79B9F (UnityPlayer) PersistentManager::LoadObjectsThreaded
0x00007FFB7DC3DD49 (UnityPlayer) LoadSceneOperation::perform
0x00007FFB7DC3D1C1 (UnityPlayer) PreloadManager::Run
0x00007FFB7DC3D4C9 (UnityPlayer) PreloadManager::Run
0x00007FFB7DC999F8 (UnityPlayer) Thread::RunThreadWrapper
0x00007FFBBA042774 (KERNEL32) BaseThreadInitThunk
0x00007FFBBC7E0D51 (ntdll) RtlUserThreadStart
========== END OF STACKTRACE ===========