Skip to content

Commit 1829753

Browse files
committed
check rgb buffer avoid crash
1 parent 6d397e3 commit 1829753

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

orbbec_camera/include/orbbec_camera/ob_camera_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,5 +421,6 @@ class OBCameraNode {
421421
std::shared_ptr<JPEGDecoder> jpeg_decoder_ = nullptr;
422422
uint8_t* rgb_buffer_ = nullptr;
423423
bool is_color_frame_decoded_ = false;
424+
std::mutex device_lock_;
424425
};
425426
} // namespace orbbec_camera

orbbec_camera/src/ob_camera_node.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void OBCameraNode::setAndGetNodeParameter(
8585
OBCameraNode::~OBCameraNode() { clean(); }
8686

8787
void OBCameraNode::clean() {
88+
std::lock_guard<decltype(device_lock_)> lock(device_lock_);
8889
RCLCPP_WARN_STREAM(logger_, "Do destroy ~OBCameraNode");
8990
is_running_.store(false);
9091
if (tf_thread_ && tf_thread_->joinable()) {
@@ -750,6 +751,10 @@ void OBCameraNode::publishColoredPointCloud(const std::shared_ptr<ob::FrameSet>
750751
}
751752

752753
void OBCameraNode::onNewFrameSetCallback(const std::shared_ptr<ob::FrameSet> &frame_set) {
754+
if (!is_running_.load()) {
755+
return;
756+
}
757+
std::lock_guard<decltype(device_lock_)> lock(device_lock_);
753758
if (frame_set == nullptr) {
754759
return;
755760
}
@@ -805,6 +810,9 @@ bool OBCameraNode::decodeColorFrameToBuffer(const std::shared_ptr<ob::Frame> &fr
805810
if (frame == nullptr) {
806811
return false;
807812
}
813+
if (!rgb_buffer_) {
814+
return false;
815+
}
808816
bool has_subscriber = image_publishers_[COLOR].getNumSubscribers() > 0;
809817
if (enable_colored_point_cloud_ && depth_registration_cloud_pub_->get_subscription_count() > 0) {
810818
has_subscriber = true;

0 commit comments

Comments
 (0)