mirror of
https://github.com/photonstorm/phaser
synced 2024-12-01 00:49:41 +00:00
Fixes #1410
As pointed out, `newChild.parent` could be accessed after it was set to undefined. This fix unifies the code from the various `destroy` methods so the previou issue does not occur.
This commit is contained in:
parent
e7f3b9188e
commit
fe8c5021fa
1 changed files with 8 additions and 9 deletions
|
@ -692,24 +692,23 @@ Phaser.Group.prototype.replace = function (oldChild, newChild) {
|
||||||
|
|
||||||
if (index !== -1)
|
if (index !== -1)
|
||||||
{
|
{
|
||||||
if (newChild.parent !== undefined)
|
if (newChild.parent)
|
||||||
{
|
{
|
||||||
newChild.events.onRemovedFromGroup$dispatch(newChild, this);
|
|
||||||
newChild.parent.removeChild(newChild);
|
|
||||||
|
|
||||||
if (newChild.parent instanceof Phaser.Group)
|
if (newChild.parent instanceof Phaser.Group)
|
||||||
{
|
{
|
||||||
newChild.parent.updateZ();
|
newChild.parent.remove(newChild);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newChild.parent.removeChild(newChild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var temp = oldChild;
|
this.remove(oldChild);
|
||||||
|
|
||||||
this.remove(temp);
|
|
||||||
|
|
||||||
this.addAt(newChild, index);
|
this.addAt(newChild, index);
|
||||||
|
|
||||||
return temp;
|
return oldChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue