From 396d6736a04addadc262d64d1b2a6db2f8177961 Mon Sep 17 00:00:00 2001 From: Folkert van Heusden Date: Sat, 7 Feb 2026 09:46:15 +0100 Subject: [PATCH] Assignment to a shared_ptr is not atomic (due to the reference counting) so locking is required. --- .../include/botcraft/AI/TemplatedBehaviourClient.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/botcraft/include/botcraft/AI/TemplatedBehaviourClient.hpp b/botcraft/include/botcraft/AI/TemplatedBehaviourClient.hpp index 6dc373e3..bd26f674 100644 --- a/botcraft/include/botcraft/AI/TemplatedBehaviourClient.hpp +++ b/botcraft/include/botcraft/AI/TemplatedBehaviourClient.hpp @@ -284,9 +284,12 @@ namespace Botcraft // We need to update the tree with the new one catch (const SwapTree&) { - tree = new_tree; - new_tree = nullptr; - swap_tree = false; + { + std::lock_guard behaviour_guard(behaviour_mutex); + tree = new_tree; + new_tree = nullptr; + swap_tree = false; + } OnTreeChanged(tree.get()); blackboard.Reset(new_blackboard); continue;