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

This commit is contained in:
Richard Davey 2019-07-03 15:47:40 +01:00
parent deca3c95a3
commit 5416deaa54

View file

@ -193,9 +193,12 @@ var UpdateList = new Class({
*/ */
update: function (time, delta) 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) if (gameObject.active)
{ {
@ -216,9 +219,7 @@ var UpdateList = new Class({
*/ */
remove: function (child) remove: function (child)
{ {
var index = this._pendingRemoval.indexOf(child); if (this._list.indexOf(child) !== -1 && this._pendingRemoval.indexOf(child) === -1)
if (index !== -1)
{ {
this._pendingRemoval.push(child); this._pendingRemoval.push(child);
} }