Multiple PulseAudio contexts cause Out of Memory #182
Labels
No labels
Bug
Extensions
New Feature
Not our bug - SDL2
Not our bug - WMA
Utilities
Wine
X3DAudio Accuracy
XACT Accuracy
XAudio2 Accuracy
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-FNA-XNA/FAudio#182
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Game Gauntlet.
When running with xaudio, the game runs out memory when trying to load character selection.
Basically the game creates a bunch of IXAudio2 CreateMasteringVoice objects, about 10.
For each CreateMasteringVoice it calls through to FAudio which in-turn calls SDL_OpenAudio().
Now, within SDL_OpenAudio, it creates a pa_context which allocates, 64MB (default pulseaudio size) for the shm buffer.
You can now see how very quickly a 32bit application will run out of memory, if these buffers hang
around for any length of time.
How could we reduce the number of pa_context that are created?
Do we really need to open the Audio device multiples times?
Yes, to the best of my knowledge this is accurate to the spec. A long time ago I tried to map multiple masters to one device, but lots of performance and compatibility issues arose from that. You can verify the native device behavior by tracing dsound/wasapi calls with the official XAudio2 DLLs.
If they’re trying to create multiple masters at the same time, that should actually be an error:
Having multiple Master is allowed as long as you use separate XAudio instances which it does for this games. I've dug a little deeper and my estimation was high, its failing on the 5th instance of XA27_CreateMasteringVoice, since it hasn't finished with the other yet, so hasn't called DestroyVoice on the master object.
There appears to be at least one case where the master voice isn't used for anything before it crashes (out of memory).
Maybe we could delay the initialization until first use?
Does it work if you set SDL_AUDIODRIVER=dummy? If so then I might actually pin this as an SDL issue (or Pulse?), since we don’t actually control the memory allocations for the platform devices. This may even work when using the SDL WASAPI backend on Windows.
Setting SDL_AUDIODRIVER=dummy, just caused a crash on startup.
Right, forgot that you can technically have only one dummy at a time... so unfortunately there’s not an easy way to compare on Linux alone. macOS and Windows would be good places to test this though.
Doing a bit of spring cleaning...
This is basically a system issue and is unique to PulseAudio - I would wager a guess that Pipewire fixes this both at the Pulse wrapper level and the direct Pipewire level as well, which SDL 2.0.16 will support. Either way, closing as NOTOURBUG.