Skip to content

Commit b28a727

Browse files
committed
Fixed Game.destroy
1 parent 9961636 commit b28a727

4 files changed

Lines changed: 52 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Please see the complete JSDocs for the ScenePlugin for more details, as well as
4545
* Group.remove didn't check if the passed Game Object was already a member of the group and would call `removeCallback` and (if specified) `destroy` in any case. Now it does nothing if the Game Object isn't a member of the group (thanks @samme)
4646
* If a Group size exceeded `maxSize` (which can happen if you reduce maxSize beneath the current size), `isFull` would return false and the group could continue to grow. Now `isFull` returns true in that case (thanks @samme)
4747
* Camera.fadeIn following a fadeOut wouldn't work, but is now fixed as a result of the Camera effects rewrite. Fix #3527 (thanks @Jerenaux)
48+
* Particle Emitters with large volumes of particles would throw the error `GL_INVALID_OPERATION: Vertex buffer is not big enough for the draw call` in WebGL.
4849

4950
### Updates
5051

src/boot/Game.js

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,26 @@ var Game = new Class({
242242
*/
243243
this.onStepCallback = NOOP;
244244

245+
/**
246+
* Is this Game pending destroy at the end of the next frame?
247+
*
248+
* @name Phaser.Game#pendingDestroy
249+
* @type {boolean}
250+
* @private
251+
* @since 3.5.0
252+
*/
253+
this.pendingDestroy = false;
254+
255+
/**
256+
* Remove the Canvas once the destroy is over?
257+
*
258+
* @name Phaser.Game#removeCanvas
259+
* @type {boolean}
260+
* @private
261+
* @since 3.5.0
262+
*/
263+
this.removeCanvas = false;
264+
245265
// Wait for the DOM Ready event, then call boot.
246266
DOMContentLoaded(this.boot.bind(this));
247267
},
@@ -354,6 +374,11 @@ var Game = new Class({
354374
*/
355375
step: function (time, delta)
356376
{
377+
if (this.pendingDestroy)
378+
{
379+
return this.runDestroy();
380+
}
381+
357382
// Global Managers
358383

359384
this.input.update(time, delta);
@@ -534,7 +559,24 @@ var Game = new Class({
534559
*/
535560
destroy: function (removeCanvas)
536561
{
537-
this.loop.destroy();
562+
this.pendingDestroy = true;
563+
this.removeCanvas = removeCanvas;
564+
565+
this.loop.stop();
566+
},
567+
568+
/**
569+
* Destroys this Phaser.Game instance, all global systems, all sub-systems and all Scenes.
570+
*
571+
* @method Phaser.Game#runDestroy
572+
* @private
573+
* @since 3.5.0
574+
*/
575+
runDestroy: function ()
576+
{
577+
this.events.emit('destroy');
578+
579+
this.events.removeAllListeners();
538580

539581
this.scene.destroy();
540582

@@ -543,16 +585,16 @@ var Game = new Class({
543585
this.renderer.destroy();
544586
}
545587

546-
this.events.emit('destroy');
547-
548-
this.events.removeAllListeners();
549-
550588
this.onStepCallback = null;
551589

552-
if (removeCanvas && this.canvas)
590+
if (this.removeCanvas && this.canvas)
553591
{
554592
CanvasPool.remove(this.canvas);
555593
}
594+
595+
this.loop.destroy();
596+
597+
this.pendingDestroy = false;
556598
}
557599

558600
});

src/scene/SceneManager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,8 @@ var SceneManager = new Class({
14801480
sys.destroy();
14811481
}
14821482

1483+
this.update = NOOP;
1484+
14831485
this.scenes = [];
14841486

14851487
this._pending = [];

src/scene/Systems.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var Class = require('../utils/Class');
88
var CONST = require('./const');
99
var GetPhysicsPlugins = require('./GetPhysicsPlugins');
1010
var GetScenePlugins = require('./GetScenePlugins');
11+
var NOOP = require('../utils/NOOP');
1112
var Plugins = require('../plugins');
1213
var Settings = require('./Settings');
1314

0 commit comments

Comments
 (0)