Skip to content

Testing new OfflineAudioContext#7255

Open
gonzalezgonzalezjorgeluis71-tech wants to merge 1 commit intophaserjs:masterfrom
gonzalezgonzalezjorgeluis71-tech:audio-revamp
Open

Testing new OfflineAudioContext#7255
gonzalezgonzalezjorgeluis71-tech wants to merge 1 commit intophaserjs:masterfrom
gonzalezgonzalezjorgeluis71-tech:audio-revamp

Conversation

@gonzalezgonzalezjorgeluis71-tech
Copy link

@gonzalezgonzalezjorgeluis71-tech gonzalezgonzalezjorgeluis71-tech commented Feb 27, 2026

Please do not update the README or Change Log, we will do this when we merge your PR.

This PR (delete as applicable)

  • Updates the Documentation
  • Adds a new feature
  • Fixes a bug

Describe the changes below:


Note

High Risk
Touches core WebAudio initialization/locking and decoding pathways; incorrect context creation or missing offlineContext wiring can break all audio playback or decoding across browsers.

Overview
Switches audio decoding for AudioFile to use an OfflineAudioContext (config.offlineContext.decodeAudioData) instead of decoding on the live playback context.

Refactors WebAudioSoundManager to create and track a new offlineContext, defer creation of the playback AudioContext until unlocked/needed, and make global mute/volume resilient when master nodes aren’t created yet (store _mute/_volume, null-guard node usage, safer destroy/update/onBlur).

Also tweaks WebAudioSound missing-audio error text and adds several debug console.log statements in the sound manager.

Written by Cursor Bugbot for commit 75ebcea. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 5 potential issues.

Bugbot Free Tier Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.


// interesting read https://github.com/WebAudio/web-audio-api/issues/1305
this.config.context.decodeAudioData(this.xhrLoader.response,
this.config.offlineContext.decodeAudioData(this.xhrLoader.response,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config property name mismatch causes audio decoding crash

High Severity

The onProcess method accesses this.config.offlineContext but the config object is constructed at line 61 with the property name context (i.e., { context: audioContext }). Since offlineContext was never set on the config, this will be undefined, and calling decodeAudioData on undefined will throw a runtime error. Every audio file load will crash.

Fix in Cursor Fix in Web

BaseSoundManager.call(this, game);

if (this.locked && game.isBooted)
this.locked = this.offlineContext.state === 'suspended';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OfflineAudioContext always suspended prevents AudioContext creation

High Severity

An OfflineAudioContext always starts in 'suspended' state per the Web Audio API spec, so this.locked at line 90 will always be true. This means createAudioContext() in the else branch (line 107) is never called. Meanwhile, the unlockHandler has the createAudioContext() call commented out (lines 347–350) and checks if (_this.context && body) — which is always false since context remains null. The AudioContext is never created, so audio can never play.

Additional Locations (1)

Fix in Cursor Fix in Web

if (this.locked && game.isBooted)
this.locked = this.offlineContext.state === 'suspended';

console.log('SM locked', this.locked);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug console.log statements left in production code

Medium Severity

Multiple console.log debug statements were left in the code: 'SM locked' (line 92), 'createAudioContext' (line 125), 'decodeAudio' (line 243), 'SM unlock' (line 337), and 'SM unlockHandler invoked' (line 345). These are clearly development/debugging aids that don't belong in production code for a framework library.

Additional Locations (2)

Fix in Cursor Fix in Web

*/
unlock: function ()
{
console.log('SM unlock');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decodeAudio calls method on null context reference

High Severity

The decodeAudio method calls this.context.decodeAudioData(...) at line 298, but this.context can now be null since the AudioContext creation is deferred. If decodeAudio is called before the context is created (which is likely given the locked-state logic issues), this will throw a TypeError.

Fix in Cursor Fix in Web


set: function (value)
{
this.masterMuteNode.gain.setValueAtTime(value ? 0 : 1, 0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing null check on context in destroy method

Medium Severity

The destroy method's first branch checks this.game.config.audio.context (the config value) and then calls this.context.suspend() without null-checking this.context. Since this.context now starts as null and may never be assigned (due to the deferred creation), calling suspend() on null will throw a TypeError. The else if branch correctly guards with this.context, but this branch does not.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants