From 5416deaa54adf98894d0d8726ff6d8b9e1833b4f Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 3 Jul 2019 15:47:40 +0100 Subject: [PATCH] The `UpdateList.remove` method wouldn't flag the Game Object for removal properly if it was active. It now checks that the Game Object is in the current update list and hasn't already been inserted into the 'pending removal' list before flagging it. Fix #4544 --- src/gameobjects/UpdateList.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gameobjects/UpdateList.js b/src/gameobjects/UpdateList.js index 4c8b28d9b..979be6d13 100644 --- a/src/gameobjects/UpdateList.js +++ b/src/gameobjects/UpdateList.js @@ -193,9 +193,12 @@ var UpdateList = new Class({ */ update: function (time, delta) { - for (var i = 0; i < this._list.length; i++) + var list = this._list; + var length = list.length; + + for (var i = 0; i < length; i++) { - var gameObject = this._list[i]; + var gameObject = list[i]; if (gameObject.active) { @@ -216,9 +219,7 @@ var UpdateList = new Class({ */ remove: function (child) { - var index = this._pendingRemoval.indexOf(child); - - if (index !== -1) + if (this._list.indexOf(child) !== -1 && this._pendingRemoval.indexOf(child) === -1) { this._pendingRemoval.push(child); }