From d972122e27d30bf7ce7f37847586539dcbcd3bce Mon Sep 17 00:00:00 2001 From: Sterling Archer Date: Sun, 31 May 2026 14:18:57 -0700 Subject: [PATCH] fix: run iOS audio primer synchronously in gesture handler, not in .then() --- game.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/game.js b/game.js index 491b84f..96ec803 100644 --- a/game.js +++ b/game.js @@ -195,7 +195,7 @@ const SFX = (() => { function primer() { if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)(); - ctx.resume().then(() => { + try { const osc = ctx.createOscillator(); const gain = ctx.createGain(); osc.connect(gain); @@ -203,7 +203,8 @@ const SFX = (() => { gain.gain.setValueAtTime(0.0001, ctx.currentTime); osc.start(ctx.currentTime); osc.stop(ctx.currentTime + 0.001); - }).catch(() => {}); + } catch(e) {} + if (ctx.state === 'suspended') ctx.resume().catch(() => {}); } function unlock() { if (!ctx) ctx = new (window.AudioContext || window.webkitAudioContext)();