Skip to content

Fix stale sound entry access#7488

Merged
BMagnu merged 1 commit into
scp-fs2open:masterfrom
BMagnu:sound_crash_fix
May 30, 2026
Merged

Fix stale sound entry access#7488
BMagnu merged 1 commit into
scp-fs2open:masterfrom
BMagnu:sound_crash_fix

Conversation

@BMagnu

@BMagnu BMagnu commented May 30, 2026

Copy link
Copy Markdown
Member

This bug could cause incorrect access to a wrong sound when a soundfile (including none.wav!) was used both in interface sounds and in gameplay sounds. There's more ways than just this sharing to induce the bug, but this is the most surefire way as playing a mission is guaranteed to unload both sets once, thus corrupting sound handles in both arrays. This can CTD, if the game tries to access a sound that was fully removed from the vector of loaded sounds (which happens if the last sound loaded gets unloaded), rather than just invalidated.

To work around the issue, there's two strategies:
Load counters, and not actually unloading a sound until all users no longer need to keep it. This is hard, as the current system isn't designed around it, and really should be done through smart pointers if someone ever attempts it rather than trying to manually re-implement it using load-count-in/decrementation.
The other way is to go through and invalidate stale indices after every unload. This is potentially a little bit less efficient, but much easier and better to maintain, and none of the sound unloads is in a frame critical path, so let's keep it simple for now.

@BMagnu BMagnu added this to the Release 26.0 milestone May 30, 2026
@BMagnu BMagnu added the fix A fix for bugs, not-a-bugs, and/or regressions. label May 30, 2026
@BMagnu BMagnu merged commit 6b43cab into scp-fs2open:master May 30, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix A fix for bugs, not-a-bugs, and/or regressions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants