Skip to content

Default blackboard entry does not create entry for locked content #942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zflat opened this issue Feb 28, 2025 · 1 comment
Open

Default blackboard entry does not create entry for locked content #942

zflat opened this issue Feb 28, 2025 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@zflat
Copy link
Contributor

zflat commented Feb 28, 2025

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="{=}" />
@facontidavide
Copy link
Collaborator

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?

@facontidavide facontidavide self-assigned this Mar 1, 2025
@facontidavide facontidavide added the enhancement New feature or request label Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants