Skip to content

Commit 236bfee

Browse files
fix #595 : improvement in blackboard/scripting types (#597)
1 parent acbc707 commit 236bfee

File tree

6 files changed

+827
-546
lines changed

6 files changed

+827
-546
lines changed

include/behaviortree_cpp/blackboard.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,29 @@ class Blackboard
170170
new_value = std::move(any_from_string);
171171
}
172172
}
173+
// check if we are doing a safe cast between numbers
174+
// for instance, it is safe to use int(100) to set
175+
// a uint8_t port, but not int(-42) or int(300)
176+
if constexpr(std::is_arithmetic_v<T>)
177+
{
178+
if(mismatching && isCastingSafe(previous_type, value))
179+
{
180+
mismatching = false;
181+
}
182+
}
173183

174184
if (mismatching)
175185
{
176186
debugMessage();
177187

178-
auto msg = StrCat("Blackboard entry [", key, "]: once declared, the type of a port"
179-
" shall not change. Previously declared type [", BT::demangle(previous_type),
188+
auto msg = StrCat("Blackboard::set(", key, "): once declared, "
189+
"the type of a port shall not change. "
190+
"Previously declared type [", BT::demangle(previous_type),
180191
"], current type [", BT::demangle(typeid(T)), "]");
181192
throw LogicError(msg);
182193
}
183194
}
184-
previous_any = std::move(new_value);
195+
new_value.copyInto(previous_any);
185196
}
186197
}
187198

0 commit comments

Comments
 (0)