Hey,
we have a strange crash regarding loading and unloading banks, while a “master” event is playing continuously and switching between referenced events using logic based on parameter.
In our “master” event, which is always playing, we want to periodically switch to different referenced events. At the time of the switch, we unload the bank containing the previously playing event, and calling load bank on the new referenced event. At the same time we set a different parameter value on the “master” event, to perform the switch to a different referenced event.
Because all these 3 steps (load, unload and parameter) happen at the same time, FMOD can crash internally causing Unity Editor to hard crash too.
Is there any mechanism to reliably detect when FMOD fully switched to playing a different event? We could have a while loop to wait for the new bank to load, but I’m not sure how to know when the previous bank can be unloaded. What makes it even more confusing is that it works on Android, using web requests for loadBank - I would expect this platform to also crash.
Seems like some race condition, but without some internal knowledge of FMOD I can’t say for sure.
We have FMOD running on a separate thread with its own update loop, so our parameter switch request is not processed instantly.
The only info we get from FMOD is: [FMOD] assert : assertion: ‘mEventInstance’ failed, including unsymbolicated stack - I can’t share it until tomorrow if it would help.
Old post:
Summary
The flow for us is as follows:
- We switched off the Setting to include referenced event assets into banks, because it was duplicating assets and increasing size
- We have a Master event playing, and it has selection logic to switch between several Referenced and non-referenced events
- Banks that contain referenced events can be loaded/unloaded at any time
- If the Master event is currently playing and we want to switch to a different event, several steps happen:
- We load a new bank if switching to a referenced event, which is inside an unloaded bank
- We unload the previous bank if switching from a referenced event
- We switch a parameter - always
- Master event is never stopped - this is most likely the reason for our crash
- In Unity Editor, an error occurs inside FMOD, when switching from a referenced to a non-referenced event - this scenario forces #2 and #3 steps (from above)
- [FMOD] assert : assertion: ‘mEventInstance’ failed - this happens inside FMOD library, so its a hard crash where Unity can’t recover
So in the Unity editor, we probably shouldn’t unload the bank contained the currently playing referenced event, because we’re running FMOD on a separate thread with its own update loop that processes our requests at a later time.
Is there any way to safely handle this? We could switch the parameter, wait for X amount of seconds (should be callback ideally), and then unload.
We’re also targeting Android on our project, and there the crash doesn’t happen at all, so it could be undefined behaviour too, basically race condition.