Fixed the issue of resource null pointer during device disconnection.

This commit is contained in:
lixiaobin
2023-10-12 19:16:48 +08:00
parent cbaf1125d4
commit 4fe1a4ed5f
2 changed files with 5 additions and 2 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ OBCameraNode::~OBCameraNode() { clean(); }
void OBCameraNode::clean() {
RCLCPP_WARN_STREAM(logger_, "Do destroy ~OBCameraNode");
is_running_.store(false);
if (tf_thread_->joinable()) {
if (tf_thread_ && tf_thread_->joinable()) {
tf_thread_->join();
}
RCLCPP_WARN_STREAM(logger_, "stop streams");
+4 -1
View File
@@ -117,10 +117,13 @@ void OBCameraNodeDriver::onDeviceConnected(const std::shared_ptr<ob::DeviceList>
try {
startDevice(device_list);
} catch (ob::Error &e) {
device_.reset();
RCLCPP_ERROR_STREAM(logger_, "startDevice failed: " << e.getMessage());
} catch (const std::exception &e) {
device_.reset();
RCLCPP_ERROR_STREAM(logger_, "startDevice failed: " << e.what());
} catch (...) {
device_.reset();
RCLCPP_ERROR_STREAM(logger_, "startDevice failed");
}
}
@@ -200,7 +203,7 @@ void OBCameraNodeDriver::resetDevice() {
while (is_alive_ && rclcpp::ok()) {
std::unique_lock<decltype(reset_device_mutex_)> lock(reset_device_mutex_);
reset_device_cond_.wait(lock,
[this]() { return !is_alive_ || !rclcpp::ok() || reset_device_flag_; });
[this]() { return !is_alive_ || !rclcpp::ok() || reset_device_flag_; });
if (!is_alive_ || !rclcpp::ok()) {
break;
}