Skip to content

Commit

Permalink
Fix removing destroyed Container child
Browse files Browse the repository at this point in the history
  • Loading branch information
samme committed Dec 4, 2023
1 parent 47d393a commit 5cd5cad
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 5cd5cad

Please sign in to comment.