Skip to content
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

Handle exceptions during device creation #11625

Merged
merged 2 commits into from Mar 28, 2023

Conversation

OhadMeir
Copy link
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
src/device.cpp Outdated
@@ -166,23 +166,31 @@ matcher_factory::create_timestamp_composite_matcher( std::vector< std::shared_pt
return std::make_shared<timestamp_composite_matcher>(matchers);
}

device::device(std::shared_ptr<context> ctx,
device::device( std::shared_ptr<context> ctx,
Copy link
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
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 IntelRealSense:development Mar 28, 2023
10 of 14 checks passed
{
_profiles_tags = lazy<std::vector<tagged_profile>>([this]() { return get_profiles_tags(); });

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
Collaborator

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
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
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.

None yet

3 participants