mirror of
https://github.com/photonstorm/phaser
synced 2024-11-28 07:31:11 +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 (newChild.parent !== undefined)
|
||||
if (newChild.parent)
|
||||
{
|
||||
newChild.events.onRemovedFromGroup$dispatch(newChild, this);
|
||||
newChild.parent.removeChild(newChild);
|
||||
|
||||
if (newChild.parent instanceof Phaser.Group)
|
||||
{
|
||||
newChild.parent.updateZ();
|
||||
newChild.parent.remove(newChild);
|
||||
}
|
||||
else
|
||||
{
|
||||
newChild.parent.removeChild(newChild);
|
||||
}
|
||||
}
|
||||
|
||||
var temp = oldChild;
|
||||
|
||||
this.remove(temp);
|
||||
this.remove(oldChild);
|
||||
|
||||
this.addAt(newChild, index);
|
||||
|
||||
return temp;
|
||||
return oldChild;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue