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
Conversation
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :-)
{ | ||
_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 ); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Superseded by PR#11636 |
[DSO-18785]
Add flag protected by a weak_ptr to verify object is still "alive" when used by callback.