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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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