From 14d56bec426788f56bcdecda582aea38b1275466 Mon Sep 17 00:00:00 2001 From: howsohazard <143410553+howsohazard@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:30:21 -0500 Subject: [PATCH] 19026: Fixes issue where entity root would sometimes not be kept (#59) --- src/Amalgam/evaluablenode/EvaluableNodeManagement.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Amalgam/evaluablenode/EvaluableNodeManagement.h b/src/Amalgam/evaluablenode/EvaluableNodeManagement.h index b47c8a95..0d345bd6 100644 --- a/src/Amalgam/evaluablenode/EvaluableNodeManagement.h +++ b/src/Amalgam/evaluablenode/EvaluableNodeManagement.h @@ -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