fix: replace raw setTimeout with tracked timers in game audio (BUG-4)

Added audioTimeout() to audio/context.ts — tracked timer set cleared on
scene destroy via clearAllAudioTimers(). Converted 20 sfx.ts + 3 voice.ts
raw setTimeout calls to audioTimeout. Converted FightScene playEntrance
timeout to trackedTimeout. Remaining setTimeout in tts.ts worker layer
and music.ts (already tracked via setMusicTimeout) are self-managing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-13 09:59:16 +00:00
co-authored by Claude Opus 4.6
parent 3c5c6c6b95
commit 8afdc2d898
5 changed files with 48 additions and 31 deletions
+14
View File
@@ -120,4 +120,18 @@ export function resetGainNodes() {
}
}
// Tracked audio timers — SFX fire-and-forget delays that must be cleaned on scene destroy
const _audioTimers = new Set<ReturnType<typeof setTimeout>>()
export function audioTimeout(fn: () => void, ms: number): ReturnType<typeof setTimeout> {
const id = setTimeout(() => { _audioTimers.delete(id); fn() }, ms)
_audioTimers.add(id)
return id
}
export function clearAllAudioTimers() {
for (const id of _audioTimers) clearTimeout(id)
_audioTimers.clear()
}
export { MUSIC_VOL, SFX_VOL }