Default blackboard entry does not create entry for locked content
zflat opened this issue · 1 comments
Describe the bug
Using the method getLockedPortContent with a node that declares the port with a default blackboard entry does not actually add an initial value to the blackboard.
How to Reproduce
The first time that getLockedPortContent is called for a key that is not added to the blackboard already, the call does not create any blackboard entry. It returns a default AnyPtrLocked which is not placed into the blackboard storage.
For example, an action can declare a port with default blackboard entry name like InputPort<Pointcloud>("cloud", "{=)", "Point cloud"). Then in the action it can access the locked content and assign it.
if(auto any_locked = getLockedPortContent("cloud"))
{
if(any_locked->empty())
{
// the entry in the blackboard hasn't been initialized yet.
// You can initialize it doing:
any_locked.assign(my_initial_pointcloud);
}But unless the XML declares the port explicitly, the value returned from getLockedPortContent will not actually be a value from blackboard storage and so the call to any_locked.assign does not persist the assignment after any_locked goes out of scope.
I think that one resolution is to create the blackboard entry in the call to getLockedPortContent if there is a mapped key.
AnyPtrLocked Blackboard::getAnyLocked(const std::string& key)
{
if(auto entry = getEntry(key))
{
return AnyPtrLocked(&entry->value, &entry->entry_mutex);
}
+ else if (auto entry = createEntryIfValidKey(key))
+ {
+ return AnyPtrLocked(&entry->value, &entry->entry_mutex);
+ }
return {};
}Workaround
Without fixing the issue, the port must be declared in the XML
<AcquirePointCloud cloud="{=}" />So, I am not sure if I agree with your suggested change, I need to think about this more carefully.
Can you create a PR with a (failing) unit test where the "issue" is being reproduced, i.e. the expected behavior?