Skip to content

Commit 64532d8

Browse files
committed
InputPlugin.clear has a new argument skipQueue which is used to avoid clearing a Game Object twice. This, combined with the fix for 4463 means you will no longer get a Cannot read property 'dragState' error if you destroy a Game Object enabled for drag where another draggable object exists. Fix phaserjs#4228
1 parent 00dbf8b commit 64532d8

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ Notes:
166166
* Changing any aspect of a Text object, such as the font size or content, wouldn't update its `hitArea` if it had been enabled for input, causing it to carry on using the old hit area size. Now, as long as the Text was created _without_ a custom hitArea, the hitArea size will be changed to match the new texture size on update. If you have provided your own custom hitArea shape, you need to modify it when the Text changes size yourself. Fix #4456 (thanks @thanh-taro and @rexrainbow)
167167
* `Camera.clearRenderToTexture` will check to see if the Scene is available before proceeding, avoiding potential errors when a Camera is destroyed multiple times during a Scene shutdown.
168168
* Destroying a Game object during its `pointerup` event handler on a touch device will no longer cause `Uncaught TypeError: Cannot read property 'localX' of undefined`. All InputPlugin process handlers now check to see if the Game Object has been destroyed at any stage and abort if it has. Fix #4463 (thanks @PatrickSachs)
169+
* `InputPlugin.clear` has a new argument `skipQueue` which is used to avoid clearing a Game Object twice. This, combined with the fix for 4463 means you will no longer get a `Cannot read property 'dragState'` error if you destroy a Game Object enabled for drag where another draggable object exists. Fix #4228 (thanks @YannCaron)
169170

170171
### Examples, Documentation and TypeScript
171172

src/input/InputPlugin.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ var InputPlugin = new Class({
494494
{
495495
current.splice(index, 1);
496496

497-
this.clear(gameObject);
497+
this.clear(gameObject, true);
498498
}
499499
}
500500

@@ -668,11 +668,14 @@ var InputPlugin = new Class({
668668
* @since 3.0.0
669669
*
670670
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object that will have its Interactive Object removed.
671+
* @param {boolean} [skipQueue=false] - Skip adding this Game Object into the removal queue?
671672
*
672673
* @return {Phaser.GameObjects.GameObject} The Game Object that had its Interactive Object removed.
673674
*/
674-
clear: function (gameObject)
675+
clear: function (gameObject, skipQueue)
675676
{
677+
if (skipQueue === undefined) { skipQueue = false; }
678+
676679
var input = gameObject.input;
677680

678681
// If GameObject.input already cleared from higher class
@@ -681,7 +684,10 @@ var InputPlugin = new Class({
681684
return;
682685
}
683686

684-
this.queueForRemoval(gameObject);
687+
if (!skipQueue)
688+
{
689+
this.queueForRemoval(gameObject);
690+
}
685691

686692
input.gameObject = undefined;
687693
input.target = undefined;

0 commit comments

Comments
 (0)