mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 08:17:35 +02:00
fix a memory leak in OctreeElement
This commit is contained in:
parent
54ff9062c0
commit
c04e653cf3
1 changed files with 12 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue