Sounds stop working after a short time playing on OS X

I am having a problem with porting an XNA/Monogame game to OS X. The sounds work on Windows and Linux.

The problem is that after a short time playing through the game, new sounds will just stop firing, and old ones will die out. A looping music will keep playing. The sounds will come back when getting back to the main menu of the game or completing/changing the level.

The problem seems to be correlated with the amount of sounds being fired. The more that I am firing in the game, the faster the sounds will break, and vice versa.

Whenever the sounds stop working, console starts filling with this over and over:

Failed to generate OpenAL data buffer: Invalid Value
Failed to generate OpenAL data buffer: Invalid Value
Failed to generate OpenAL data buffer: Invalid Value

So far what I have done is:

  • Cloned the Monogame repository, compiled the code with Release configuration, and linked those binaries to the game. Not working.
  • I have commented out all other uses of SoundEffect.Play() and Resume() except one, where I have hard coded all parameters like this: MySoundEffect.Play(volume: 0.5f, pitch: 0, pan: 0); The MySoundEffect is also never disposed or used in any other way. -> Does not help.

I have a Macbook Air 13-inch Mid 2012, running OS X 10.10 Yosemite. Unfortunately I do not have another Mac readily available for testing.

Any help would be highly appreciated.

My main dev laptop is a MacBook Pro. Do you have a sample game you can send or link to? Even better, have a single-file game that shows the issue? I’ll try to reproduce in my environment and see if I can find where things are blowing up.

Ideally, you’d have an example that consistently fails after some formulaic process. (e.g. An MP3 loops in the background as sound effects are fired every N seconds. Expect to observe failure after X seconds, when the application log starts filling up with OpenAL data buffer errors.)

Don’t get your hopes up. I’m not an audio expert, and I make my living in Windows. But OS X is my primary MonoGame dev environment, so I’ve got a little skin in the game. :slight_smile:

Hey, and thank you for replying.

The main game fails consistently on my machine after less than 30 seconds in to a level when firing as much as possible. We also made a single-file sound tester application which can be used to bombard different sounds at different intervals. It is clear that it can fill the sound buffer up for a while, but unfortunately I can never get the sounds to die completely like it happens in the game.

By a sample game you probable mean the actual source code? Unfortunately my team (I am mainly helping with the OS X port) does not feel comfortable about sharing source code of the whole game, and it would take quite a bit of effort to strip it down to the bare essentials. This is after all an otherwise releasable game and the Windows version is on sale.

We could of course send you the binary version of the game but with some limited content just to get the download size down, but I do not see how it would help with debugging. Or would it?

However, I may have a new lead. For the first time it occurred to me that I should check activity monitor for the game’s memory consumption. Without firing, memory consumption will rise very slowly if at all. When firing aggressively, memory consumption will also rise aggressively. At the same time as the sounds die, memory consumption will hit a ceiling at about 600MB and will refuse to get any higher.

I’ll just do a little tinkering based on your descriptions. If you find a solution before me, be sure to post it.

Our problems indeed seem to have been due to the memory consumption. As soon as I realized that, we noticed that the pooling of SoundEffectInstances did not seem to work. We now have at least a decent fix in place to the MonoGame’s SoundEffectInstancePool class, so it reuses the instances instead of allocating new memory for each one.

Will see about posting the resolution here and/or issuing a pull request later. Now I am off to bed, excited to finally having figured out this game breaking issue that has been nagging us for a while. :slight_smile:

I’m working on the same project and the sound issue indeed seems to be caused by the sound memory allocation.

I forced all sounds to use sounds from SoundInstancePool and removed the soundBuffer = new OALSoundBuffer(); from InitialzeSound and moved it to soundInstance constructor, which greatly reduced the memory usage and allowed the sounds to work again correctly on Mac. However it seems like I created some new problems with this “fix”. Like music not starting sometimes and 3D sounds seem to no longer work after playing for a while. The game also still seems to be generating quite a bit of garbage which doesn’t get removed by garbage collector. The game was 700+ MBs on mac just after 3 stages and 500 MBs on Linux after 20 or so. The game never uses over 300 MBs of ram when playing on Windows and XNA.

EDIT: I just confirmed that the memory leak is sound related at least on Linux, as there wasn’t any increase on memory usage after muting sounds

Sounds like you found the cause, but not the solution? Are one of you guys planning to do track down the problem, create a fix, and then post a patch / pull request to github?

If not, let me know. I think you’ve given enough information to reproduce on OS X and Linux. But I’m guessing that you want a fix sooner than this hobbyist would be able to recreate and repair the issue.

Short version: I don’t mind doing the legwork. But I don’t want to duplicate your efforts if you’re planning to submit a fix. And I don’t want to be a bottleneck for your project.

Our solution is quite messy at this point, so it isn’t github-ready I’m afraid. Sounds seem to work now but memory consumption may still be an issue.

But as far as I understand the problem is that the “SoundEffectInstancePool” is not really working like a pool at all, but instead it just allocates new memory for each sound played.

Hi, same issue here.

Keep in mind that the SoundEffectInstance’s purpose is to limit memory consumption by reusing the same chunk of memory. On monogame for Mac it seems to allocate new memory every time so i soon hit crashes and memory issues.

This is something that need to be fixed in monogame framework, otherwise devs will not able to pack their games :wink:

Thank you guys!