From fa8ad51c794a9b0e68da100cc8070a679c5b5e89 Mon Sep 17 00:00:00 2001 From: Mario Gonzalez Date: Mon, 30 Sep 2013 22:06:48 -0400 Subject: [PATCH] Fixed bug in LinkedList#remove that could cause first/tail to be have pointers to dead node --- src/core/LinkedList.js | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/src/core/LinkedList.js b/src/core/LinkedList.js index 1cf214ce3..23eb1d1c7 100644 --- a/src/core/LinkedList.js +++ b/src/core/LinkedList.js @@ -38,37 +38,19 @@ Phaser.LinkedList.prototype = { }, remove: function (child) { - - // If the list is empty - if (this.first == null && this.last == null) - { - return; - } + if( this.first ) { + child.next = this.last.next; + child.prev = this.last; + if( this.last.next ) { + this.last.next.prev = child; + } + this.last.next = child; + this.last = this.last.next; + } else { + this.first = this.last = child; + } this.total--; - - // The only node? - if (this.first == child && this.last == child) - { - this.first = null; - this.last = null; - this.next = null; - child.next = null; - child.prev = null; - return; - } - - var childPrev = child.prev; - - // Tail node? - if (child.next) - { - // Has another node after it? - child.next.prev = child.prev; - } - - childPrev.next = child.next; - }, callAll: function (callback) {