Skip to content

Handle exceptions during device creation - #11625

Merged
Nir-Az merged 2 commits into
realsenseai:developmentfrom
OhadMeir:development
Mar 28, 2023
Merged

Nir-Az merged 2 commits into
realsenseai:developmentfrom
OhadMeir:development

Conversation

@OhadMeir

Copy link
Copy Markdown
Contributor

[DSO-18785]

Add flag protected by a weak_ptr to verify object is still "alive" when used by callback.

@OhadMeir
OhadMeir requested a review from Nir-Az March 28, 2023 09:44
Comment thread src/device.cpp Outdated
}

device::device(std::shared_ptr<context> ctx,
device::device( std::shared_ptr<context> ctx,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we avoid unrelated format changes for this PR?
Lets focus on the main changes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Although I do prefer to fix bad formatting where I make changes anyway. Could be more easily compared in the VSCode view :-)

@Nir-Az
Nir-Az merged commit f0ac4be into realsenseai:development Mar 28, 2023
Comment thread src/device.cpp
if (_device_changed_notifications)
{
auto cb = new devices_changed_callback_internal([this](rs2_device_list* removed, rs2_device_list* added)
std::weak_ptr< bool > weak = std::make_shared< bool >( _is_alive );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This shouldn't work!
Make the shared - good.
Make the weak - good.
Destroy the shared - because nobody's holding it!
Now in the callback, weak.lock() has no strong pointer alive, it will return null...
@OhadMeir please review

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You are right.
I think we missed that

bool _is_alive;

should be

std::shared_ptr<bool> _is_alive;

and add the _alive(make_shared<bool>(true)).. in the Ctor or something like that.

@OhadMeir OhadMeir mentioned this pull request Mar 30, 2023
@OhadMeir

Copy link
Copy Markdown
Contributor Author

Superseded by PR#11636

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