Skip to content

RSDK-11289: Fix logic in replace_one #463

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

Merged
merged 6 commits into from
Jul 14, 2025
Merged

RSDK-11289: Fix logic in replace_one #463

merged 6 commits into from
Jul 14, 2025

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 stuqdog and gabegottlob 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.

@@ -58,7 +58,15 @@ class ResourceManager {
/// @brief Replaces an existing resource. No-op if the named resource does not exist.
/// @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
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.

2 participants