Skip to content

Commit 2b6ecba

Browse files
committed
fix issue #433
1 parent ef68cf1 commit 2b6ecba

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/blackboard.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ void Blackboard::setPortInfo(std::string key, const PortInfo& info)
1212
if( remapping_it != internal_to_external_.end())
1313
{
1414
parent->setPortInfo( remapping_it->second, info );
15+
return;
1516
}
1617
}
1718

@@ -25,15 +26,25 @@ void Blackboard::setPortInfo(std::string key, const PortInfo& info)
2526
if( old_type && old_type != info.type() )
2627
{
2728
throw LogicError( "Blackboard::set() failed: once declared, the type of a port shall not change. "
28-
"Declared type [", BT::demangle( old_type ),
29-
"] != current type [", BT::demangle( info.type() ), "]" );
29+
"Previously declared type [", BT::demangle( old_type ),
30+
"] != new type [", BT::demangle( info.type() ), "]" );
3031
}
3132
}
3233
}
3334

3435
const PortInfo* Blackboard::portInfo(const std::string &key)
3536
{
3637
std::unique_lock<std::mutex> lock(mutex_);
38+
39+
if( auto parent = parent_bb_.lock())
40+
{
41+
auto remapping_it = internal_to_external_.find(key);
42+
if( remapping_it != internal_to_external_.end())
43+
{
44+
return parent->portInfo( remapping_it->second );
45+
}
46+
}
47+
3748
auto it = storage_.find(key);
3849
if( it == storage_.end() )
3950
{

tests/gtest_subtree.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,5 +275,41 @@ TEST(SubTree, SubtreePlusD)
275275
ASSERT_EQ(ret, BT::NodeStatus::SUCCESS);
276276
}
277277

278+
TEST(SubTree, SubtreeIssue433)
279+
{
280+
BT::NodeConfiguration config;
281+
config.blackboard = BT::Blackboard::create();
282+
static const char* xml_text = R"(
283+
284+
<root main_tree_to_execute = "TestTree" >
285+
<BehaviorTree ID="Subtree1">
286+
<Decorator ID="Repeat" num_cycles="{port_to_use}">
287+
<Action ID="AlwaysSuccess"/>
288+
</Decorator>
289+
</BehaviorTree>
290+
291+
<BehaviorTree ID="Subtree2">
292+
<Action ID="SetBlackboard" output_key="test_port" value="{port_to_read}"/>
293+
</BehaviorTree>
294+
295+
<BehaviorTree ID="TestTree">
296+
<Sequence>
297+
<Action ID="SetBlackboard" output_key="test_port" value="1"/>
298+
<SubTree ID="Subtree1" port_to_use="test_port"/>
299+
<SubTree ID="Subtree2" port_to_read="test_port"/>
300+
</Sequence>
301+
</BehaviorTree>
302+
</root> )";
303+
304+
BT::BehaviorTreeFactory factory;
305+
306+
BT::Tree tree = factory.createTreeFromText(xml_text, config.blackboard);
307+
auto ret = tree.tickRoot();
308+
309+
ASSERT_EQ(ret, BT::NodeStatus::SUCCESS);
310+
}
311+
312+
313+
278314

279315

0 commit comments

Comments
 (0)