Skip to content

Commit 3219b6f

Browse files
committed
fix issue #702 : output ports require {}
1 parent 11e9d1a commit 3219b6f

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

include/behaviortree_cpp/actions/set_blackboard_node.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ class SetBlackboard : public SyncActionNode
5555
{
5656
throw RuntimeError("missing port [value]");
5757
}
58-
setOutput("output_key", value);
58+
59+
config().blackboard->set(static_cast<std::string>(key), value);
60+
5961
return NodeStatus::SUCCESS;
6062
}
6163
};

include/behaviortree_cpp/tree_node.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,16 @@ inline Result TreeNode::setOutput(const std::string& key, const T& value)
486486
StringView remapped_key = remap_it->second;
487487
if (remapped_key == "=")
488488
{
489-
remapped_key = key;
489+
config().blackboard->set(static_cast<std::string>(key), value);
490+
return {};
490491
}
491-
if (isBlackboardPointer(remapped_key))
492+
493+
if (!isBlackboardPointer(remapped_key))
492494
{
493-
remapped_key = stripBlackboardPointer(remapped_key);
495+
return nonstd::make_unexpected("setOutput requires a blackboard pointer. Use {}");
494496
}
497+
498+
remapped_key = stripBlackboardPointer(remapped_key);
495499
config().blackboard->set(static_cast<std::string>(remapped_key), value);
496500

497501
return {};

src/blackboard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ AnyPtrLocked Blackboard::getAnyLocked(const std::string &key) const
2121
{
2222
if(auto entry = getEntry(key))
2323
{
24-
return AnyPtrLocked(&entry->value, const_cast<std::mutex*>(&entry->entry_mutex));
24+
return AnyPtrLocked(&entry->value, const_cast<std::mutex*>(&entry->entry_mutex));
2525
}
2626
return {};
2727
}

tests/gtest_blackboard.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,5 +459,22 @@ TEST(BlackboardTest, IssueSetBlackboard)
459459
ASSERT_EQ(42, tree.rootBlackboard()->get<int>("value"));
460460
}
461461

462+
TEST(BlackboardTest, NullOutputRemapping)
463+
{
464+
auto bb = Blackboard::create();
465+
466+
NodeConfig config;
467+
468+
config.blackboard = bb;
469+
config.input_ports["in_port"] = "{my_input_port}";
470+
config.output_ports["out_port"] = "";
471+
bb->set("my_input_port", 11);
472+
473+
BB_TestNode node("good_one", config);
474+
475+
// This will throw because setOutput should fail in BB_TestNode::tick()
476+
ASSERT_ANY_THROW(node.executeTick());
477+
}
478+
462479

463480

0 commit comments

Comments
 (0)