From a5aea72a17ca959d256b245da1cf81b02dea3311 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 25 Mar 2024 01:04:07 +0100 Subject: [PATCH] Plan: Fix syncing derived plan sometimes fails on var rename --- blackboard/blackboard_plan.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/blackboard/blackboard_plan.cpp b/blackboard/blackboard_plan.cpp index d1122f7..a430187 100644 --- a/blackboard/blackboard_plan.cpp +++ b/blackboard/blackboard_plan.cpp @@ -140,6 +140,7 @@ bool BlackboardPlan::is_prefetching_nodepath_vars() const { } void BlackboardPlan::add_var(const StringName &p_name, const BBVariable &p_var) { + ERR_FAIL_COND(p_name == StringName()); ERR_FAIL_COND(var_map.has(p_name)); var_map.insert(p_name, p_var); var_list.push_back(Pair(p_name, p_var)); @@ -198,6 +199,7 @@ void BlackboardPlan::rename_var(const StringName &p_name, const StringName &p_ne ERR_FAIL_COND(!is_valid_var_name(p_new_name)); ERR_FAIL_COND(!var_map.has(p_name)); + ERR_FAIL_COND(var_map.has(p_new_name)); BBVariable var = var_map[p_name]; Pair new_entry(p_new_name, var); @@ -270,12 +272,17 @@ void BlackboardPlan::sync_with_base_plan() { } // Erase variables that do not exist in the base plan. + List erase_list; for (const Pair &p : var_list) { if (!base->has_var(p.first)) { - remove_var(p.first); + erase_list.push_back(p.first); changed = true; } } + while (erase_list.size()) { + remove_var(erase_list.front()->get()); + erase_list.pop_front(); + } // Sync order of variables. // Glossary: E - element of current plan, B - element of base plan, F - element of current plan (used for forward search).