From 168e1e3a322595eed2ce9c5145a28e9e5c775678 Mon Sep 17 00:00:00 2001 From: Dorian Date: Sun, 8 Mar 2026 01:21:12 +0000 Subject: [PATCH] fix: kill in-flight SFX when navigating away from fight Disconnect and recreate sfxGain in stopAllAudio() so oscillators and noise buffers stop immediately instead of playing to completion. Co-Authored-By: Claude Opus 4.6 --- frontend/src/game/sounds.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontend/src/game/sounds.ts b/frontend/src/game/sounds.ts index 852a780..81abe06 100644 --- a/frontend/src/game/sounds.ts +++ b/frontend/src/game/sounds.ts @@ -340,6 +340,14 @@ export function stopAllAudio() { stopMusic() if (typeof speechSynthesis !== 'undefined') speechSynthesis.cancel() _speechQueueDepth = 0 + // Disconnect sfxGain to instantly kill all in-flight oscillators/buffers, + // then reconnect so future sounds still work + if (sfxGain && ctx) { + sfxGain.disconnect() + sfxGain = ctx.createGain() + sfxGain.gain.value = masterMuted ? 0 : 0.25 + sfxGain.connect(ctx.destination) + } } // Public voice functions