fix a memory leak in OctreeElement

This commit is contained in:
Stephen Birarda 2014-11-07 17:06:50 -08:00
parent 54ff9062c0
commit c04e653cf3

View file

@ -69,6 +69,7 @@ void OctreeElement::init(unsigned char * octalCode) {
_childBitmask = 0;
_childrenExternal = false;
#ifdef BLENDED_UNION_CHILDREN
_children.external = NULL;
_singleChildrenCount++;
@ -661,6 +662,11 @@ void OctreeElement::deleteAllChildren() {
}
}
if (_childrenExternal) {
// if the children_t union represents _children.external we need to delete it here
delete[] _children.external;
}
#ifdef BLENDED_UNION_CHILDREN
// now, reset our internal state and ANY and all population data
int childCount = getChildCount();
@ -758,13 +764,18 @@ void OctreeElement::setChildAtIndex(int childIndex, OctreeElement* child) {
_children.external[firstIndex] = previousChild;
_children.external[childIndex] = child;
_childrenExternal = true;
_externalChildrenMemoryUsage += NUMBER_OF_CHILDREN * sizeof(OctreeElement*);
} else if (previousChildCount == 2 && newChildCount == 1) {
assert(!child); // we are removing a child, so this must be true!
OctreeElement* previousFirstChild = _children.external[firstIndex];
OctreeElement* previousSecondChild = _children.external[secondIndex];
delete[] _children.external;
_childrenExternal = false;
_externalChildrenMemoryUsage -= NUMBER_OF_CHILDREN * sizeof(OctreeElement*);
if (childIndex == firstIndex) {
_children.single = previousSecondChild;