Skip to content

Commit 0b1fb5a

Browse files
committed
Destroying an object with an input handler during its onDown event would throw Signals dispatch errors (thanks @jflowers45, fix phaserjs#746)
InputHandler._setHandCursor private var wasn't properly set, meaning the hand cursor could sometimes remain (during destroy sequence for example) All Game Objects have a new property: destroyPhase (boolean) which is true if the object is in the process of being destroyed, otherwise false. The PIXI.AbstractFilter is now included in the Phaser Pixi build by default, allowing for easier use of external Pixi Filters.
1 parent a582f21 commit 0b1fb5a

10 files changed

Lines changed: 155 additions & 19 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ We have a new [Getting Started Guide](http://phaser.io/getting-started-js.php) w
4747

4848
We wrote a comprehensive [How to Learn Phaser](http://gamedevelopment.tutsplus.com/articles/how-to-learn-the-phaser-html5-game-engine--gamedev-13643) guide for GameDevTuts+ which covers finding tutorials, examples and support.
4949

50-
Finally the growing list of [community authored Phaser Tutorials](http://www.lessmilk.com/phaser-tutorial/) is growing fast!
50+
The [Game Mechanic Explorer](http://gamemechanicexplorer.com) is a great interactive way to learn how to develop specific game mechanics in Phaser. Well worth exploring once you've got your dev environment set-up.
51+
52+
Finally the list of [community authored Phaser Tutorials](http://www.lessmilk.com/phaser-tutorial/) is growing fast!
5153

5254
![Phaser Logo](http://www.photonstorm.com/wp-content/uploads/2013/09/phaser_10_release.jpg)
5355

@@ -70,6 +72,8 @@ Version 2.0.4 - "Mos Shirare" - in development
7072
* ArcadePhysics.collideSpriteVsGroup checks if Sprite has a body before carrying on, now safely skips sub-groups or other non-Sprite group children.
7173
* Group.remove now checks the child to see if it's a member of the root Group before removing it, otherwise Pixi throws an Error.
7274
* The Emitter no longer checks if minParticleScale = maxParticleScale for the scale check, allowing for fixed scale particles again.
75+
* The PIXI.AbstractFilter is now included in the Phaser Pixi build by default, allowing for easier use of external Pixi Filters.
76+
* All Game Objects have a new property: destroyPhase (boolean) which is true if the object is in the process of being destroyed, otherwise false.
7377

7478

7579
### New Features
@@ -94,6 +98,8 @@ Version 2.0.4 - "Mos Shirare" - in development
9498
* Line.angle and Math.angleBetween used Math.atan2 arguments in the wrong order (thanks @jotson, fix #724)
9599
* Group.destroy checks parent before removing (thanks @clark-stevenson, fix #733)
96100
* Fixed typo in P2.World.setMaterial (thanks @OpherV, fix #739)
101+
* InputHandler._setHandCursor private var wasn't properly set, meaning the hand cursor could sometimes remain (during destroy sequence for example)
102+
* Destroying an object with an input handler during its onDown event would throw Signals dispatch errors (thanks @jflowers45, fix #746)
97103

98104

99105
### ToDo

src/core/Group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ Phaser.Group.prototype.remove = function (child, destroy) {
14301430
return false;
14311431
}
14321432

1433-
if (child.events)
1433+
if (child.events && !child.destroyPhase)
14341434
{
14351435
child.events.onRemovedFromGroup.dispatch(child, this);
14361436
}

src/gameobjects/BitmapText.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ Phaser.BitmapText = function (game, x, y, font, text, size) {
123123
* 5 = outOfBoundsFired (0 = no, 1 = yes)
124124
* 6 = exists (0 = no, 1 = yes)
125125
* 7 = fixed to camera (0 = no, 1 = yes)
126+
* 8 = destroy phase? (0 = no, 1 = yes)
126127
* @property {Array} _cache
127128
* @private
128129
*/
129-
this._cache = [0, 0, 0, 0, 1, 0, 1, 0];
130+
this._cache = [0, 0, 0, 0, 1, 0, 1, 0, 0];
130131

131132
};
132133

@@ -210,10 +211,12 @@ Phaser.BitmapText.prototype.postUpdate = function () {
210211
*/
211212
Phaser.BitmapText.prototype.destroy = function(destroyChildren) {
212213

213-
if (this.game === null) { return; }
214+
if (this.game === null || this.destroyPhase) { return; }
214215

215216
if (typeof destroyChildren === 'undefined') { destroyChildren = true; }
216217

218+
this._cache[8] = 1;
219+
217220
if (this.parent)
218221
{
219222
if (this.parent instanceof Phaser.Group)
@@ -257,6 +260,8 @@ Phaser.BitmapText.prototype.destroy = function(destroyChildren) {
257260
this.mask = null;
258261
this.game = null;
259262

263+
this._cache[8] = 0;
264+
260265
};
261266

262267
/**
@@ -464,3 +469,17 @@ Object.defineProperty(Phaser.BitmapText.prototype, "fixedToCamera", {
464469
}
465470

466471
});
472+
473+
/**
474+
* @name Phaser.BitmapText#destroyPhase
475+
* @property {boolean} destroyPhase - True if this object is currently being destroyed.
476+
*/
477+
Object.defineProperty(Phaser.BitmapText.prototype, "destroyPhase", {
478+
479+
get: function () {
480+
481+
return !!this._cache[8];
482+
483+
}
484+
485+
});

src/gameobjects/Graphics.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ Phaser.Graphics = function (game, x, y) {
7171
* 5 = outOfBoundsFired (0 = no, 1 = yes)
7272
* 6 = exists (0 = no, 1 = yes)
7373
* 7 = fixed to camera (0 = no, 1 = yes)
74+
* 8 = destroy phase? (0 = no, 1 = yes)
7475
* @property {Array} _cache
7576
* @private
7677
*/
77-
this._cache = [ 0, 0, 0, 0, 1, 0, 1, 0 ];
78+
this._cache = [ 0, 0, 0, 0, 1, 0, 1, 0, 0 ];
7879

7980
};
8081

@@ -147,8 +148,12 @@ Phaser.Graphics.prototype.postUpdate = function () {
147148
*/
148149
Phaser.Graphics.prototype.destroy = function(destroyChildren) {
149150

151+
if (this.game === null || this.destroyPhase) { return; }
152+
150153
if (typeof destroyChildren === 'undefined') { destroyChildren = true; }
151154

155+
this._cache[8] = 1;
156+
152157
this.clear();
153158

154159
if (this.parent)
@@ -185,6 +190,8 @@ Phaser.Graphics.prototype.destroy = function(destroyChildren) {
185190

186191
this.game = null;
187192

193+
this._cache[8] = 0;
194+
188195
};
189196

190197
/*
@@ -254,3 +261,17 @@ Object.defineProperty(Phaser.Graphics.prototype, "fixedToCamera", {
254261
}
255262

256263
});
264+
265+
/**
266+
* @name Phaser.Graphics#destroyPhase
267+
* @property {boolean} destroyPhase - True if this object is currently being destroyed.
268+
*/
269+
Object.defineProperty(Phaser.Graphics.prototype, "destroyPhase", {
270+
271+
get: function () {
272+
273+
return !!this._cache[8];
274+
275+
}
276+
277+
});

src/gameobjects/Image.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,11 @@ Phaser.Image = function (game, x, y, key, frame) {
115115
* 5 = outOfBoundsFired (0 = no, 1 = yes)
116116
* 6 = exists (0 = no, 1 = yes)
117117
* 7 = fixed to camera (0 = no, 1 = yes)
118+
* 8 = destroy phase? (0 = no, 1 = yes)
118119
* @property {Array} _cache
119120
* @private
120121
*/
121-
this._cache = [ 0, 0, 0, 0, 1, 0, 1, 0 ];
122+
this._cache = [ 0, 0, 0, 0, 1, 0, 1, 0, 0 ];
122123

123124
};
124125

@@ -387,10 +388,12 @@ Phaser.Image.prototype.kill = function() {
387388
*/
388389
Phaser.Image.prototype.destroy = function(destroyChildren) {
389390

390-
if (this.game === null) { return; }
391+
if (this.game === null || this.destroyPhase) { return; }
391392

392393
if (typeof destroyChildren === 'undefined') { destroyChildren = true; }
393394

395+
this._cache[8] = 1;
396+
394397
if (this.parent)
395398
{
396399
if (this.parent instanceof Phaser.Group)
@@ -438,6 +441,8 @@ Phaser.Image.prototype.destroy = function(destroyChildren) {
438441
this.mask = null;
439442
this.game = null;
440443

444+
this._cache[8] = 0;
445+
441446
};
442447

443448
/**
@@ -768,3 +773,17 @@ Object.defineProperty(Phaser.Image.prototype, "smoothed", {
768773
}
769774

770775
});
776+
777+
/**
778+
* @name Phaser.Image#destroyPhase
779+
* @property {boolean} destroyPhase - True if this object is currently being destroyed.
780+
*/
781+
Object.defineProperty(Phaser.Image.prototype, "destroyPhase", {
782+
783+
get: function () {
784+
785+
return !!this._cache[8];
786+
787+
}
788+
789+
});

src/gameobjects/Sprite.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ Phaser.Sprite = function (game, x, y, key, frame) {
165165
* 5 = outOfBoundsFired (0 = no, 1 = yes)
166166
* 6 = exists (0 = no, 1 = yes)
167167
* 7 = fixed to camera (0 = no, 1 = yes)
168+
* 8 = destroy phase? (0 = no, 1 = yes)
168169
* @property {Array} _cache
169170
* @private
170171
*/
171-
this._cache = [ 0, 0, 0, 0, 1, 0, 1, 0 ];
172+
this._cache = [ 0, 0, 0, 0, 1, 0, 1, 0, 0 ];
172173

173174
/**
174175
* @property {Phaser.Rectangle} _bounds - Internal cache var.
@@ -516,10 +517,12 @@ Phaser.Sprite.prototype.kill = function() {
516517
*/
517518
Phaser.Sprite.prototype.destroy = function(destroyChildren) {
518519

519-
if (this.game === null) { return; }
520+
if (this.game === null || this._cache[8] === 1) { return; }
520521

521522
if (typeof destroyChildren === 'undefined') { destroyChildren = true; }
522523

524+
this._cache[8] = 1;
525+
523526
if (this.parent)
524527
{
525528
if (this.parent instanceof Phaser.Group)
@@ -577,6 +580,8 @@ Phaser.Sprite.prototype.destroy = function(destroyChildren) {
577580
this.mask = null;
578581
this.game = null;
579582

583+
this._cache[8] = 0;
584+
580585
};
581586

582587
/**
@@ -1060,3 +1065,17 @@ Object.defineProperty(Phaser.Sprite.prototype, "y", {
10601065
}
10611066

10621067
});
1068+
1069+
/**
1070+
* @name Phaser.Sprite#destroyPhase
1071+
* @property {boolean} destroyPhase - True if this object is currently being destroyed.
1072+
*/
1073+
Object.defineProperty(Phaser.Sprite.prototype, "destroyPhase", {
1074+
1075+
get: function () {
1076+
1077+
return !!this._cache[8];
1078+
1079+
}
1080+
1081+
});

src/gameobjects/Text.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ Phaser.Text = function (game, x, y, text, style) {
128128
* 5 = outOfBoundsFired (0 = no, 1 = yes)
129129
* 6 = exists (0 = no, 1 = yes)
130130
* 7 = fixed to camera (0 = no, 1 = yes)
131+
* 8 = destroy phase? (0 = no, 1 = yes)
131132
* @property {Array} _cache
132133
* @private
133134
*/
134-
this._cache = [ 0, 0, 0, 0, 1, 0, 1, 0 ];
135+
this._cache = [ 0, 0, 0, 0, 1, 0, 1, 0, 0 ];
135136

136137
};
137138

@@ -213,10 +214,12 @@ Phaser.Text.prototype.postUpdate = function () {
213214
*/
214215
Phaser.Text.prototype.destroy = function (destroyChildren) {
215216

216-
if (this.game === null) { return; }
217+
if (this.game === null || this.destroyPhase) { return; }
217218

218219
if (typeof destroyChildren === 'undefined') { destroyChildren = true; }
219220

221+
this._cache[8] = 1;
222+
220223
if (this.parent)
221224
{
222225
if (this.parent instanceof Phaser.Group)
@@ -265,6 +268,8 @@ Phaser.Text.prototype.destroy = function (destroyChildren) {
265268
this.mask = null;
266269
this.game = null;
267270

271+
this._cache[8] = 0;
272+
268273
};
269274

270275
/**
@@ -886,3 +891,17 @@ Object.defineProperty(Phaser.Text.prototype, "fixedToCamera", {
886891
}
887892

888893
});
894+
895+
/**
896+
* @name Phaser.Text#destroyPhase
897+
* @property {boolean} destroyPhase - True if this object is currently being destroyed.
898+
*/
899+
Object.defineProperty(Phaser.Text.prototype, "destroyPhase", {
900+
901+
get: function () {
902+
903+
return !!this._cache[8];
904+
905+
}
906+
907+
});

src/gameobjects/TileSprite.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ Phaser.TileSprite = function (game, x, y, width, height, key, frame) {
145145
* 5 = outOfBoundsFired (0 = no, 1 = yes)
146146
* 6 = exists (0 = no, 1 = yes)
147147
* 7 = fixed to camera (0 = no, 1 = yes)
148+
* 8 = destroy phase? (0 = no, 1 = yes)
148149
* @property {Array} _cache
149150
* @private
150151
*/
151-
this._cache = [ 0, 0, 0, 0, 1, 0, 1, 0 ];
152+
this._cache = [ 0, 0, 0, 0, 1, 0, 1, 0, 0 ];
152153

153154
};
154155

@@ -402,10 +403,12 @@ Phaser.TileSprite.prototype.loadTexture = function (key, frame) {
402403
*/
403404
Phaser.TileSprite.prototype.destroy = function(destroyChildren) {
404405

405-
if (this.game === null) { return; }
406+
if (this.game === null || this.destroyPhase) { return; }
406407

407408
if (typeof destroyChildren === 'undefined') { destroyChildren = true; }
408409

410+
this._cache[8] = 1;
411+
409412
if (this.filters)
410413
{
411414
this.filters = null;
@@ -451,6 +454,8 @@ Phaser.TileSprite.prototype.destroy = function(destroyChildren) {
451454
this.mask = null;
452455
this.game = null;
453456

457+
this._cache[8] = 0;
458+
454459
};
455460

456461
/**
@@ -745,3 +750,17 @@ Object.defineProperty(Phaser.TileSprite.prototype, "y", {
745750
}
746751

747752
});
753+
754+
/**
755+
* @name Phaser.TileSprite#destroyPhase
756+
* @property {boolean} destroyPhase - True if this object is currently being destroyed.
757+
*/
758+
Object.defineProperty(Phaser.TileSprite.prototype, "destroyPhase", {
759+
760+
get: function () {
761+
762+
return !!this._cache[8];
763+
764+
}
765+
766+
});

0 commit comments

Comments
 (0)