Skip to content

Commit

Permalink
Merge pull request #6686 from samme/fix/container-destroy-child
Browse files Browse the repository at this point in the history
Fix removing destroyed Container children
  • Loading branch information
photonstorm authored Jan 12, 2024
2 parents 8cae5a3 + 5cd5cad commit e91551b
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/gameobjects/container/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ var Container = new Class({
*/
addHandler: function (gameObject)
{
gameObject.once(Events.DESTROY, this.remove, this);
gameObject.once(Events.DESTROY, this.onChildDestroyed, this);

if (this.exclusive)
{
Expand Down Expand Up @@ -976,7 +976,7 @@ var Container = new Class({
{
if (list[i] && list[i].scene)
{
list[i].off(Events.DESTROY, this.remove, this);
list[i].off(Events.DESTROY, this.onChildDestroyed, this);

list[i].destroy();
}
Expand Down Expand Up @@ -1452,6 +1452,25 @@ var Container = new Class({
this.tempTransformMatrix.destroy();

this.list = [];
},

/**
* Internal handler, called when a child is destroyed.
*
* @method Phaser.GameObjects.Container#onChildDestroyed
* @protected
* @since 3.70.1
*/
onChildDestroyed: function (gameObject)
{
ArrayUtils.Remove(this.list, gameObject);

if (this.exclusive)
{
gameObject.parentContainer = null;

gameObject.removedFromScene();
}
}

});
Expand Down

0 comments on commit e91551b

Please sign in to comment.