From b61d6cf4e81e638fde710853fdbd2af608d5cb75 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 21 May 2013 11:48:30 -0700 Subject: [PATCH] cleanup code --- libraries/voxels/src/VoxelTree.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 5a8ed2368a..b398e89d61 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -100,6 +100,8 @@ VoxelNode * VoxelTree::nodeForOctalCode(VoxelNode *ancestorNode, unsigned char * // returns the node created! VoxelNode* VoxelTree::createMissingNode(VoxelNode* lastParentNode, unsigned char* codeToReach) { int indexOfNewChild = branchIndexWithDescendant(lastParentNode->getOctalCode(), codeToReach); + // If this parent node is a leaf, then you know the child path doesn't exist, so deal with + // breaking up the leaf first, which will also create a child path if (lastParentNode->isLeaf() && lastParentNode->isColored()) { // for colored leaves, we must add *all* the children for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { @@ -107,6 +109,7 @@ VoxelNode* VoxelTree::createMissingNode(VoxelNode* lastParentNode, unsigned char lastParentNode->getChildAtIndex(i)->setColor(lastParentNode->getColor()); } } else if (!lastParentNode->getChildAtIndex(indexOfNewChild)) { + // we could be coming down a branch that was already created, so don't stomp on it. lastParentNode->addChildAtIndex(indexOfNewChild); }