Check for removal of children in the traverse method
See original GitHub issueDescription of the problem
Removing children while using the traverse function will result in an error. I propose a second check to make sure that l = children inside the loop, in case a node is removed. Original:
traverse: function ( callback ) {
callback( this );
var children = this.children;
for ( var i = 0, l = children.length; i < l; i ++ ) {
children[ i ].traverse( callback );
}
}
My proposal:
traverse: function ( callback ) {
callback( this );
var children = this.children;
for ( var i = 0, l = children.length; i < l; i ++ ) {
if(l != children.length){
l=children.length;
i--;
}
children[ i ].traverse( callback );
}
}
There might be a better way to do it, but that change got my code working.
Three.js version
- Dev
- r94
- …
Browser
- All of them
- Chrome
- Firefox
- Internet Explorer
OS
- All of them
- Windows
- macOS
- Linux
- Android
- iOS
Hardware Requirements (graphics card, VR Device, …)
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Traversing the DOM children of children - Stack Overflow
Being that it the children property returns a list, you can access the individual nodes in the collection by using either the item()...
Read more >Check for Children Sum Property in a Binary Tree
Given a binary tree, the task is to check for every node, its value is equal to the sum of values of its...
Read more >jQuery Traversing Descendants - W3Schools
With jQuery you can traverse down the DOM tree to find descendants of an element. A descendant is a child, grandchild, great-grandchild, and...
Read more >Methods of Depth First Traversal and Their Applications
If the node (19) has a left node, we'll traverse it; it does, and its left node (12) has a left node (7)...
Read more >Operations on Binary Search Tree's
There are several methods of traversing trees. Among them are the inorder, preorder and postorder traversal of nodes. Each of these traversal algorithms...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@looeee IMHO, that is not necessary. It is reasonable to expect users to understand the ramifications of modifying a graph while traversing it. Same with an array. Save yourself some work. 😃
@jkulanko If you need further help, please use the forum.
Closing, as this is a user error.
@aardgoose I’m going to have to look into that because that seems like it might be a very good solution to my problem, thanks!
@looeee That wouldn’t quite work for me, because of my unique situation. I am receiving an individual part asynchronously from a backserver which contains a mesh and a line. Each of the parts is a leaf node to a larger tree structure, and therefore needs to take into account the matrices of its parent (or many parents). So I want to keep each mesh and line segments together in a single object as that represents one leaf.