Skip to content

Commit

Permalink
19026: Fixes issue where entity root would sometimes not be kept (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
howsohazard authored Jan 18, 2024
1 parent 467d51f commit 14d56be
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Amalgam/evaluablenode/EvaluableNodeManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -725,18 +725,19 @@ class EvaluableNodeManager
Concurrency::WriteLock lock(managerAttributesMutex);
#endif

//if currently has a root node, free it
if(firstUnusedNodeIndex > 0)
FreeNodeReference(nodes[0]);

KeepNodeReference(new_root);

//iteratively search forward; this will be fast for newly created entities but potentially slow for those that are not
// however, this should be rarely called on those entities since it's basically clearing them out, so it should not generally be a performance issue
auto location = std::find(begin(nodes), begin(nodes) + firstUnusedNodeIndex, new_root);

//swap the pointers
//put the new root in the proper place
if(location != end(nodes))
std::swap(*begin(nodes), *location);

//free old root
FreeNodeReference(*location);
}

//returns a copy of the nodes referenced; should be used only for debugging
Expand Down

0 comments on commit 14d56be

Please sign in to comment.