Skip to content

Commit bc55428

Browse files
committed
Check pendingDestroy in headlessStep()
Fixes phaserjs#4804
1 parent e762a89 commit bc55428

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

src/core/Game.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ var Game = new Class({
8888

8989
/**
9090
* A reference to an HTML Div Element used as the DOM Element Container.
91-
*
91+
*
9292
* Only set if `createDOMContainer` is `true` in the game config (by default it is `false`) and
9393
* if you provide a parent element to insert the Phaser Game inside.
9494
*
@@ -244,7 +244,7 @@ var Game = new Class({
244244
* An instance of the base Sound Manager.
245245
*
246246
* The Sound Manager is a global system responsible for the playback and updating of all audio in your game.
247-
*
247+
*
248248
* You can disable the inclusion of the Sound Manager in your build by toggling the webpack `FEATURE_SOUND` flag.
249249
*
250250
* @name Phaser.Game#sound
@@ -286,7 +286,7 @@ var Game = new Class({
286286
{
287287
/**
288288
* An instance of the Facebook Instant Games Plugin.
289-
*
289+
*
290290
* This will only be available if the plugin has been built into Phaser,
291291
* or you're using the special Facebook Instant Games custom build.
292292
*
@@ -519,6 +519,11 @@ var Game = new Class({
519519
*/
520520
headlessStep: function (time, delta)
521521
{
522+
if (this.pendingDestroy)
523+
{
524+
return this.runDestroy();
525+
}
526+
522527
var eventEmitter = this.events;
523528

524529
// Global Managers
@@ -604,12 +609,12 @@ var Game = new Class({
604609

605610
/**
606611
* Returns the current game frame.
607-
*
612+
*
608613
* When the game starts running, the frame is incremented every time Request Animation Frame, or Set Timeout, fires.
609614
*
610615
* @method Phaser.Game#getFrame
611616
* @since 3.16.0
612-
*
617+
*
613618
* @return {number} The current game frame.
614619
*/
615620
getFrame: function ()
@@ -622,7 +627,7 @@ var Game = new Class({
622627
*
623628
* @method Phaser.Game#getTime
624629
* @since 3.16.0
625-
*
630+
*
626631
* @return {number} The current game timestamp.
627632
*/
628633
getTime: function ()
@@ -632,11 +637,11 @@ var Game = new Class({
632637

633638
/**
634639
* Flags this Game instance as needing to be destroyed on the _next frame_, making this an asynchronous operation.
635-
*
640+
*
636641
* It will wait until the current frame has completed and then call `runDestroy` internally.
637-
*
642+
*
638643
* If you need to react to the games eventual destruction, listen for the `DESTROY` event.
639-
*
644+
*
640645
* If you **do not** need to run Phaser again on the same web page you can set the `noReturn` argument to `true` and it will free-up
641646
* memory being held by the core Phaser plugins. If you do need to create another game instance on the same page, leave this as `false`.
642647
*
@@ -650,7 +655,7 @@ var Game = new Class({
650655
destroy: function (removeCanvas, noReturn)
651656
{
652657
if (noReturn === undefined) { noReturn = false; }
653-
658+
654659
this.pendingDestroy = true;
655660

656661
this.removeCanvas = removeCanvas;
@@ -693,7 +698,7 @@ var Game = new Class({
693698
}
694699

695700
this.loop.destroy();
696-
701+
697702
this.pendingDestroy = false;
698703
}
699704

0 commit comments

Comments
 (0)