BehaviorTree/BehaviorTree.CPP

" blackboard->get<T>(key); "caused a crash

MoYuJiang51 opened this issue · 2 comments

I created a thread in the project to retrieve the values of specific blackboard variables at intervals of 20ms, check for changes, and log them. However, I encountered intermittent crashes without being able to identify the cause. Below are the code and stack trace.
Code:
template
bool RobotStatusPublisher::UpdatePlanInfoKeyValue(const std::string& key, T& value) {
auto blackboard = myBlackboard::GetInstance().GetBlackBoard();
T tmp_value = blackboard->get(key);
if (value != tmp_value) {
value = tmp_value;
return true;
}
return false;
}

Crash 1:
: bool RobotStatusPublisher::UpdatePlanInfoKeyValue<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator >&) [clone .isra.0]
Crash 2:
: nonstd::expected_liite::expected<std::__cxx11::basic_string<char, std::char_traits, std::allocattor >, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > BT::Any::convert<std::_cxx11::basic_string<char,
std::char_traits, std::allocator > >(std::enable_if<std::is_same<std::
cxx11::basic string<char,std::char_traits,
std::allocator >, std:: __cxx11::basic_string<char, std::char_traits, std::allocator > >::value, void>::type*) const
: bool RobotStatusPublisher: UpdatePlanInfoKeyValue<std::__cxx11::basic string<char, std::char_traits, std::allocator > >(std::__cxx11::basic_string<char, std::char_traits,_std::allocator > const&, std:: __cxx11::basic string<char, std::char_traits, std::allocator >&)
20240731-190907

Can you explain what the problem was?

Can you explain what the problem was?

Here's the situation: the version I'm using is not the latest version. The function being called is 'T get(const std::string& key) const'. Inside the function, 'getAny(key);' is locked, but the return value is a pointer. I suspect that a crash occurred due to other threads modifying 'Any' during cost, so I added an overloaded function to 'getAny': 'bool getAny(const std::string& key, Any& copy) const,' which returns a temporary variable. Currently, no crashes have occurred during my self-testing."
image