Merge pull request #1283 from ZappoMan/keep_local_voxels

fix potential crashing bug related to incorrectly initialized memory
This commit is contained in:
Andrzej Kapolka 2013-11-21 11:28:55 -08:00
commit ea467c5341

View file

@ -510,6 +510,7 @@ void VoxelNode::storeTwoChildren(VoxelNode* childOne, VoxelNode* childTwo) {
const int newChildCount = 2;
_externalChildrenMemoryUsage += newChildCount * sizeof(VoxelNode*);
_children.external = new VoxelNode*[newChildCount];
memset(_children.external, 0, sizeof(VoxelNode*) * newChildCount);
}
_children.external[0] = childOne;
_children.external[1] = childTwo;
@ -620,6 +621,7 @@ void VoxelNode::storeThreeChildren(VoxelNode* childOne, VoxelNode* childTwo, Vox
const int newChildCount = 3;
_externalChildrenMemoryUsage += newChildCount * sizeof(VoxelNode*);
_children.external = new VoxelNode*[newChildCount];
memset(_children.external, 0, sizeof(VoxelNode*) * newChildCount);
}
_children.external[0] = childOne;
_children.external[1] = childTwo;
@ -1004,6 +1006,8 @@ void VoxelNode::setChildAtIndex(int childIndex, VoxelNode* child) {
_childrenExternal = true;
const int newChildCount = 4;
_children.external = new VoxelNode*[newChildCount];
memset(_children.external, 0, sizeof(VoxelNode*) * newChildCount);
_externalChildrenMemoryUsage += newChildCount * sizeof(VoxelNode*);
_children.external[0] = childOne;
@ -1072,6 +1076,7 @@ void VoxelNode::setChildAtIndex(int childIndex, VoxelNode* child) {
// 4 or more children, one item being added, we know we're stored externally, we just figure out where to insert
// this child pointer into our external list
VoxelNode** newExternalList = new VoxelNode*[newChildCount];
memset(newExternalList, 0, sizeof(VoxelNode*) * newChildCount);
int copiedCount = 0;
for (int ordinal = 1; ordinal <= newChildCount; ordinal++) {