I’ve been trying to reproduce it in a smaller project but haven’t had any luck. I did track down a reproducible case in the full project that does speak to something the game may be doing to get into a weird state but nothing is jumping out at me.
The game hard crashes when the audio source is being paused.
The setup is a prefab with multiple audio sources on children, each with a reference to an audio random container asset. The ARCs are primarily used as playlists in this use case, with each ARC holding a list of audio clips to play sequentially. In practice, only one of the ARCs has multiple clips within it. At runtime, the prefab lives in DontDestroyOnLoad nested inside another parent prefab that is a singleton.
The purpose is to crossfade music when moving between scenes. The issue occurs when leaving the main area of the game and its music fades out.
High level flow of logic:
- The script on the prefab with references to all the audio sources subscribes to SceneManager.sceneLoaded in OnEnable.
- When the sceneLoaded event is raised, the next scene is checked against a list and, if there is a match, a cross fade between audio sources happens between the current and next appropriate audio source
- The next audio source has Play called on it
- The old audio fades out while the new audio fades in
- At the end of fading out, the audio source is either paused or stopped
- If the scene is not the main scene, the audioSource is stopped
- If the scene is the main scene, the audioSource is paused so that it’s position in the playlist can be preserved
- The game crashes in the audio update after the call to pause
- The game does not get this crash if the audioSource is stopped
The fades are handled by DOTween in this case, but the crash happens even if Pause is called immediately, with DOTween entirely removed, so I do not have reason to believe the fading itself or mechanism for fading out is related.
The call stack from the crash dump with references to closed platforms removed:
AudioRandomContainerRuntime::CleanUpFinishedClipPlayables() Line 321 (0x1D369E0CFC)|C++
AudioRandomContainerRuntime::Update() Line 544 (0x1D369E2FB4)|C++|
AudioManager::Update() Line 2651 (0x1D36A0888C)|C++|
AudioModule::Update() Line 34 (0x1D369D0B1C)|C++|
ExecutePlayerLoop(NativePlayerLoopSystem* system) Line 409 (0x1D3627B934)|C++|
ExecutePlayerLoop(NativePlayerLoopSystem* system) Line 430 (0x1D3627B978)|C++|
PlayerLoop() Line 537 (0x1D3627BBE8)|C++|
Main() Line 690 (0x1D3677568C)|C++|
and the native exception
0x00000002: Access Violation of Data
I can confirm that the clip that is being cleaned up in the stack frame is one from the main are’s ARC, based on the length of the clip as visible in local variables. And, as mentioned, changing Pause to Stop prevents the crash entirely.
I’ll continue to try and get this reproducing in a smaller project to share, though my focus now is to replace the use of ARC on the main music playback with a simple playlist component to get things moving with the development team.