diff --git a/src/audio/audio_audiomanager.js b/src/audio/audio_audiomanager.js index 882667f071c..a7f087860cd 100644 --- a/src/audio/audio_audiomanager.js +++ b/src/audio/audio_audiomanager.js @@ -64,7 +64,7 @@ pc.extend(pc, function () { } } this.listener = new pc.Listener(this); - + this.volume = 1; this.suspended = false; @@ -95,7 +95,7 @@ pc.extend(pc, function () { } return sound; }, - + /** * @private @@ -151,7 +151,7 @@ pc.extend(pc, function () { } channel.play(); } - + return channel; }, @@ -160,7 +160,7 @@ pc.extend(pc, function () { }, getVolume: function () { - return this.volume; + return this.volume; }, setVolume: function (volume) { @@ -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; + } } }; diff --git a/src/framework/framework_application.js b/src/framework/framework_application.js index 367a2cea6e6..e7eb86e319b 100644 --- a/src/framework/framework_application.js +++ b/src/framework/framework_application.js @@ -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) { @@ -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(); } diff --git a/src/resources/resources_loader.js b/src/resources/resources_loader.js index 53484137d91..bed33e447a7 100644 --- a/src/resources/resources_loader.js +++ b/src/resources/resources_loader.js @@ -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);