CreateJS / SoundJS

A Javascript library for working with Audio. It provides a consistent API for loading and playing audio on different browsers and devices. Currently supports WebAudio, HTML5 Audio, Cordova / PhoneGap, and a Flash fallback.
http://createjs.com/
MIT License
4.44k stars 835 forks source link

Bug in AbstractPlugin._handlePreloadComplete(event). #269

Closed xpol closed 6 years ago

xpol commented 7 years ago

The current code:

    p._handlePreloadComplete = function (event) {
        var src = event.target.getItem().src;
        this._audioSources[src] = event.result;
        for (var i = 0, l = this._soundInstances[src].length; i < l; i++) {
            var item = this._soundInstances[src][i];
            item.setPlaybackResource(this._audioSources[src]);
            // ToDo consider adding play call here if playstate == playfailed
            this._soundInstances[src] = null;
        }
    };

The line this._soundInstances[src] = null; will cause index null in next loop at line var item = this._soundInstances[src][i];

lannymcnie commented 7 years ago

This is an easy addition, but what was your steps to get into this situation? I would like to ensure the fix is tested properly.

ie, it is unclear if we should be splicing the current instance out of the array, or moving the line out of the if() so it deletes it once it has set the playbackResource on all audio sources.

gSkinner-Blair commented 6 years ago

Was fixed in a83ffe7e87af110cb45cc4814d80451db804ee3d

phd-hub commented 4 years ago

This still seems to be a problem in version 1.0.0: https://code.createjs.com/1.0.0/soundjs.js

curiousdustin commented 3 years ago

This is closed, but did it ever make it into a version?

How do I use a version with this fix?

NeilFraser commented 2 years ago

Confirming this fix never made it to the code in https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.min.js or https://code.createjs.com/1.0.0/soundjs.min.js The fix landed one month after the last publish date.

Our users are routinely observing this error (though I've never been able to recreate it myself): TypeError: Cannot read properties of null (reading '1') SoundJS/soundjs.min.js 18:15312

Can the contents of /lib be regenerated?

NeilFraser commented 2 years ago

@curiousdustin One approach to get this code is to use a monkey patch. Just load the published version, then in your code add the following:

  createjs.AbstractPlugin.prototype._handlePreloadComplete = function(e) {
    var src = e.target.getItem().src;
    var result = e.result;
    var instances = this._soundInstances[src];
    this._audioSources[src] = result;

    if (instances != null && instances.length > 0) {
      for (var i=0, l=instances.length; i<l; i++) {
        instances[i].playbackResource = result;
      }
    }
    this._soundInstances[src] = null;
  };