Skip to content

Conversation

@lia-viam
Copy link
Collaborator

@lia-viam lia-viam commented Jul 11, 2025

third time's the charm? this should finally fix the always-rebuild logic in ReconfigureResource, making sure that the old resource is destructed before the new one is created. this was causing issues with realsense and would cause issues for any other unique or global resource which has sole ownership of a device, socket, etc.

this adds an overload of replace_one which takes a construction callback, bringing the logic closer to that of eg python
https://github.com/viamrobotics/viam-python-sdk/blob/main/src/viam/module/module.py#L253

i marked the old one as deprecated for now but we may just want to remove it entirely

cc @hexbabe @acmorrow

@lia-viam lia-viam requested a review from a team as a code owner July 11, 2025 20:34
@lia-viam lia-viam requested review from gabegottlob and stuqdog and removed request for a team July 11, 2025 20:34
@lia-viam lia-viam changed the title Fix logic in replace_one RSDK-11289: Fix logic in replace_one Jul 11, 2025
Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm though I think we should probably just get rid of the deprecated replace_one if it doesn't work.

/// @param name The name of the resource to replace.
/// @param resource The new resource that is replacing the existing one.
void replace_one(const Name& name, std::shared_ptr<Resource> resource);
[[deprecated("Use the callback overload as it destroys before constructing")]] void replace_one(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if this overload doesn't work correctly we should just get rid of it entirely.

@lia-viam lia-viam merged commit eee87b6 into main Jul 14, 2025
5 checks passed
@lia-viam lia-viam deleted the replace-one-fix branch July 14, 2025 16:13
@atlassian
Copy link

atlassian bot commented Sep 22, 2025

🔗 Link your GitHub account to Atlassian

To enable Code Reviewer, please link your GitHub account to your Atlassian account.

Click here to connect your accounts

This is a one-time setup that takes less than a minute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants