Skip to content

Commit

Permalink
Destroy audio manager when application is destroyed, Better handling …
Browse files Browse the repository at this point in the history
…of destroying application while resources are being preloaded
  • Loading branch information
vkalpias committed Jun 4, 2015
1 parent da1a3db commit 2db3716
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/audio/audio_audiomanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pc.extend(pc, function () {
}
}
this.listener = new pc.Listener(this);

this.volume = 1;
this.suspended = false;

Expand Down Expand Up @@ -95,7 +95,7 @@ pc.extend(pc, function () {
}
return sound;
},


/**
* @private
Expand Down Expand Up @@ -151,7 +151,7 @@ pc.extend(pc, function () {
}
channel.play();
}

return channel;
},

Expand All @@ -160,7 +160,7 @@ pc.extend(pc, function () {
},

getVolume: function () {
return this.volume;
return this.volume;
},

setVolume: function (volume) {
Expand All @@ -176,6 +176,13 @@ pc.extend(pc, function () {
resume: function () {
this.suspended = false;
this.fire('resume');
},

destroy: function () {
if (this.context && this.context.close) {
this.context.close();
this.context = null;
}
}
};

Expand Down
15 changes: 12 additions & 3 deletions src/framework/framework_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,23 @@ pc.extend(pc, function () {

// check if all loading is done
var done = function () {
// do not proceed if application destroyed
if (!self.graphicsDevice) {
return;
}

if (!_done && _assets.done() && _scripts.done()) {
_done = true;
self.systems.script.preloading = false;
callback();
}
}
};

// totals loading progress of assets and scripts
var total = assets.length + this._scripts.length;
var count = function () {
return _assets.count + _scripts.count;
}
};

var i;
if (_assets.length) {
Expand Down Expand Up @@ -841,7 +846,11 @@ pc.extend(pc, function () {
this.graphicsDevice = null;

this.renderer = null;
this._audioManager = null;

if (this._audioManager) {
this._audioManager.destroy();
this._audioManager = null;
}

pc.net.http = new pc.net.Http();
}
Expand Down
6 changes: 6 additions & 0 deletions src/resources/resources_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ pc.extend(pc, function () {
// new request
this._requests[key] = [callback];
handler.load(url, function (err, data) {
// make sure key exists because loader
// might have been destroyed by now
if (!this._requests[key]) {
return;
}

var i, len = this._requests[key].length;
if (!err) {
var resource = handler.open(url, data);
Expand Down

0 comments on commit 2db3716

Please sign in to comment.