Android 2.03.14: crash in `sem_post` when the app goes to the background

Since we upgraded from FMOD 2.02.28 to 2.03.14 in July, our Android app has been crashing now and then when it goes to the background. It’s a segmentation fault inside sem_post in the system C library. The code that calls it isn’t visible in our crash reports, but everything points to FMOD. So far it’s been about 50 crashes across several device types and Android versions. We never saw it on 2.02.28, and it doesn’t happen on iOS or Windows.

The odd part is that it doesn’t seem to depend much on what we do when the app goes to the background. We’ve tried three approaches, and all of them crashed:

  1. Only muting the master channel group. No mixerSuspend at all.
  2. Calling mixerSuspend() when going to the background, and mixerResume() when coming back.
  3. Calling flushCommands() first, then mixerSuspend(), with nothing else of ours touching FMOD at the same time. Here our logs show the crash happening within a few milliseconds of mixerSuspend starting. Often mixerSuspend still returns OK afterwards, so it looks like another thread is the one crashing.

The third case sounds a lot like Crash in mixerSuspend. But since we also saw it with no mixerSuspend at all, we suspect the same problem can be hit some other way as well, maybe when FMOD rebuilds its audio output on its own.

Following the suggestion in that thread, our latest release pauses the master channel group on Android instead of suspending the mixer:

// Going to the background
coreSystem.getMasterChannelGroup(out ChannelGroup master);
master.setPaused(true);

// Coming back
master.setPaused(false);

It’s too early to say how much that helps. Given case 1, our guess is that it will reduce the crashes but not get rid of them completely. We’ll post an update once we have more data.

It would be great to hear when the fix from the other thread is expected to land. If our case 1 sounds like something that fix wouldn’t cover, we’re happy to help track it down.

I replied to a majorty of this here Crash in mixerSuspend - #13 by jeff_fmod
But in any case, thanks for giving the workaround a shot, and we expect the new release to be available in about a month.
I have uploaded temporary non-QA-approved builds to your FMOD profile for the interim, and it would be great to hear how you go with them.

Thanks a lot, Jeff, and great to hear that you might have found and fixed a potential culprit race condition. I will download the files, and see if we can make the issue completely disappear. The crash is rather random and rare, so it may take a while to get sufficient comfort that this fixes the problem completely. However, if we do happen to experience a further crash one way or the other, then we at least know that the problem persists.