Jump to content

Group.removeBetween iterates erroneously


localGhost
 Share

Recommended Posts

It is very awkward to say this, but for me it looks like current implementation of this function is bugged. Probably no one uses it anyway or it would be long found :)

The thing is that the code falls in a very trivial trap: it changes the array it is iterating over:

 for (var i = startIndex; i < endIndex; i++)    {        if (this.children[i].events)        {            this.children[i].events.onRemovedFromGroup.dispatch(this.children[i], this);        }        this.removeChild(this.children[i]);        if (this.cursor === this.children[i])        {            this.cursor = null;        }    }

removeChild line will shift the indexes, if I'm not mistaken. Eventually the loop fails on accessing .events for non-existant (out of bounds) child.

 

Also it seems reasonable to make second parameter optional, just removing every item starting with startIndex.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...