Skip to content

Muting a sound before it has ever been played crashes the game in Firefox 31 (and possibly previous versions and other browsers too) #1108

@osmanzeki

Description

@osmanzeki

Hello,

The problem seems to occur when a dev tries to unmute a sound that has not yet been muted. In Chrome, this doesn't crash the game but it does in Firefox (possibly in other browsers without V8-like behaviour).

This is the error that you would usually get :

TypeError: Value being assigned to AudioParam.value is not a finite floating-point value.

This error occurs because the property this._muteVolume is undefined at that point as it is only dynamically created when Sound.mute = true is set beforehand.

The code that is causing this error is as follows (Sound.js :: http://docs.phaser.io/Sound.js.html#sunlight-1-line-843):

value = value || null;

if (value)
{
    this._muted = true;

    if (this.usingWebAudio)
    {
        this._muteVolume = this.gainNode.gain.value;
        this.gainNode.gain.value = 0;
    }
    else if (this.usingAudioTag && this._sound)
    {
        this._muteVolume = this._sound.volume;
        this._sound.volume = 0;
    }
}
else
{
    this._muted = false;

    if (this.usingWebAudio)
    {
        this.gainNode.gain.value = this._muteVolume;
    }
    else if (this.usingAudioTag && this._sound)
    {
        this._sound.volume = this._muteVolume;
    }
}

this.onMute.dispatch(this);

I believe a simple fix to this issue would be to add a line such as this one to the Sound classe's initial closure function (as well as any other class that uses this internal property) :

    /**
    * @property {number} _muteVolume - Internal marker var.
    * @private
    */
    this._muteVolume = 0;

If the mute property is ever set to true, the the this._muteVolume property would be overriden with this line of code :

this._muteVolume = this.gainNode.gain.value;
this.gainNode.gain.value = 0;

And if not, it would already be set to 0 instead of undefined (which seems to be what cause the crash in Firefox).

I can create a pull request for this patch, but I'd rather have some opinion about this beforehand. I will temporarily fix this issue by either muting the sound first and then unmuting or adding the suggested line of code in my local version of Sound.js.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions