Skip to content

Commit 6501206

Browse files
committed
warn about overwritten enums
1 parent 56c6ffc commit 6501206

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/bt_factory.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,21 @@ void BehaviorTreeFactory::addMetadataToManifest(const std::string& node_id,
448448

449449
void BehaviorTreeFactory::registerScriptingEnum(StringView name, int value)
450450
{
451-
(*_p->scripting_enums)[std::string(name)] = value;
451+
const auto str = std::string(name);
452+
auto it = _p->scripting_enums->find(str);
453+
if(it == _p->scripting_enums->end())
454+
{
455+
_p->scripting_enums->insert({ str, value });
456+
}
457+
else
458+
{
459+
if(it->second != value)
460+
{
461+
throw LogicError(
462+
StrCat("Registering the enum [", name, "] twice with different values, first ",
463+
std::to_string(it->second), " and later ", std::to_string(value)));
464+
}
465+
}
452466
}
453467

454468
void BehaviorTreeFactory::clearSubstitutionRules()

0 commit comments

Comments
 (0)