Skip to content

Fix use-after-free crash in audio synthesis on level reset (#133)#197

Merged
KiritoDv merged 1 commit into
HarbourMasters:developfrom
JeodC:fix/audiorace
May 30, 2026
Merged

Fix use-after-free crash in audio synthesis on level reset (#133)#197
KiritoDv merged 1 commit into
HarbourMasters:developfrom
JeodC:fix/audiorace

Conversation

@JeodC

@JeodC JeodC commented May 30, 2026

Copy link
Copy Markdown
Contributor

sound_reset() runs on the game thread and synchronously calls audio_reset_session() (reinitializes the audio heap / note pool) while the audio thread is mid-synthesis_process_notes -> final_resample -> aResampleImpl, reading freed sample memory.

Added GameEngine_LockAudioThread/Unlock bridges that take the same audio.mutex HandleAudioThread holds during synthesis, and wrapped sound_reset()'s body with them. The reset now waits for any in-flight resample frame, and the next synthesis frame waits for the reset to finish.

sound_reset is only ever called from the game thread, so there's no audio-thread re-entrancy / deadlock.

Addresses #133

@KiritoDv KiritoDv merged commit 5bdf803 into HarbourMasters:develop May 30, 2026
4 of 5 checks passed
@JeodC JeodC deleted the fix/audiorace branch May 30, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants