FMOD crash when loading/unloading banks

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.

Hi,

Thank you for the information and reproduction steps.

Could I please grab your Unity and FMOD integration versions please?

There have recently been some fixes related to bank loading:

  • 2.03.04 - Studio API - Fixed a crash caused by changing an event via live update and then unloading one of its assets banks.
  • 2.03.03 - Studio API - Fixed a crash when unloading an assets bank before its associated metadata bank.
  • 2.03.01 - Studio API - Fixed a crash when unloading a bank containing a global parameter that automates a modulator property on another global parameter.

Both versions are on 2.02.26

Currently it’s a bit impractical to update to a newer version, so we would like to investigate possible alternatives.

Maybe the problem can be first simplified to an easier case first, where you unload a bank while an event from that bank is playing. Is it safe to do this, or if it’s not, is stopping of an event an immediate operation or also queued to be processed by the FMOD system tick?

Is there a documentation page that explains which API calls are delayed? This would help a lot to determine what’s blocking and processed instantly.

Thanks for the info.

Unlading a bank should stop and release any events created with it: FMOD Engine | Studio Api Bank - Studio:: bank::Unload, so it should be safe to unload it with playing events. When building your banks are they split into metadata and asset banks? FMOD Studio | Getting Events Into Your Game - Building Metadata And Assets To Separate Banks

Commands are added to a queue, it is possible to flush the queue with: FMOD Engine | Studio Api System - Studio::System::Flushcommands.

FMOD Engine | Studio Api Threads - Studio Asynchronous Mode