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;