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
+4 -2
View File
@@ -32,7 +32,7 @@ import {
sfxJetpack, sfxExplosion, sfxBlock, sfxDodge, sfxClash, sfxRandomSilly,
sfxBoing, sfxBonk, sfxZap, sfxSlideDown, sfxSlideUp, sfxZoomWhoosh,
sfxRapidPunch, sfxPowerUp, sfxCoin, sfxRandomComedy,
startMusic, stopMusic, announceCool,
startMusic, stopMusic, announceCool, clearAllAudioTimers,
} from './audio'
@@ -1225,7 +1225,7 @@ export async function createFightScene(config: FightSceneConfig) {
// Timeout entrance to prevent hanging on mobile (max 8s)
await Promise.race([
entranceSystem.playEntrance(),
new Promise<void>(r => setTimeout(r, 8000)),
new Promise<void>(r => trackedTimeout(r, 8000)),
])
},
@@ -1285,6 +1285,8 @@ export async function createFightScene(config: FightSceneConfig) {
clearTimeout(id)
}
cleanupTimers.clear()
// Clear audio timers (SFX/voice stagger delays)
clearAllAudioTimers()
// Destroy all remaining game objects before quitting
try { k.get('*').forEach(o => { if (o.exists()) o.destroy() }) } catch {}
k.quit()