Fix emulator freeze after iOS auto screen lock#66
Open
bokunoibasho wants to merge 1 commit into
Open
Conversation
On iOS Safari, an auto screen lock can leave the AudioContext with state === "running" while the ScriptProcessor's onaudioprocess callback permanently stops firing. The emulator's audio buffer then stays full, audioUnderrunAdjustment() throttles CPUCyclesTotal down to 0 cycles per timer iteration, and emulation appears frozen with all inputs unresponsive even though the core setInterval is still ticking. This reuses the existing watchdog primitive that was already in place to recover Firefox/Mac OS X's "node randomly stops playing" bug -- the recovery path (XAudioJSWebAudioWatchDogLast is updated from inside the audio callback, so timeDiff > 500ms is a reliable "node is dead" signal) applies equally to the iOS case. Two tiny changes: - Drop the Gecko-only userAgent gate so the watchdog runs everywhere. - Treat the iOS-specific state name "interrupted" the same as "suspended" so the context gets resumed on lock release too. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On iOS Safari, an auto screen lock leaves the
AudioContextreportingstate === 'running'while theScriptProcessorcallback permanently stops firing. The audio buffer stays full,audioUnderrunAdjustment()throttlesCPUCyclesTotaldown to 0, and the emulator looks frozen on resume.The existing
setupWebAudiowatchdog (originally for the Firefox/macOS scriptnode bug) already has the right recovery:XAudioJSWebAudioWatchDogLastis updated from inside the audio callback, sotimeDiff > 500msis a generic "node is dead" signal — it was just gated to Gecko. Two changes inmodules/XAudioJS/XAudioServer.js:navigator.userAgent.indexOf('Gecko/')gate so the watchdog runs everywhere.state === 'interrupted'the same as'suspended'for context resume.Net: +8 / −9 lines, single file.
iOS requires a user gesture to actually re-activate audio, so the user still has to tap once after unlock — but that single tap then reliably unsticks playback.
Test plan