mirror of
https://github.com/orbbec/OrbbecSDK_ROS2.git
synced 2026-10-07 21:37:46 +08:00
fix: improve null checks and error handling in OBCameraNode methods
This commit is contained in:
@@ -2633,10 +2633,20 @@ void OBCameraNode::publishDepthPointCloud(const std::shared_ptr<ob::FrameSet> &f
|
||||
RCLCPP_ERROR_STREAM(logger_, "depth frame is null");
|
||||
return;
|
||||
}
|
||||
CHECK_NOTNULL(pipeline_);
|
||||
if (!pipeline_) {
|
||||
RCLCPP_ERROR_STREAM(logger_, "pipeline is null in publishDepthPointCloud");
|
||||
return;
|
||||
}
|
||||
auto camera_params = pipeline_->getCameraParam();
|
||||
if (!device_) {
|
||||
RCLCPP_ERROR_STREAM(logger_, "device is null in publishDepthPointCloud");
|
||||
return;
|
||||
}
|
||||
auto device_info = device_->getDeviceInfo();
|
||||
CHECK_NOTNULL(device_info.get());
|
||||
if (!device_info || !device_info.get()) {
|
||||
RCLCPP_ERROR_STREAM(logger_, "device_info is null in publishDepthPointCloud");
|
||||
return;
|
||||
}
|
||||
auto pid = device_info->pid();
|
||||
if (depth_registration_ || pid == DABAI_MAX_PID) {
|
||||
camera_params.depthIntrinsic = camera_params.rgbIntrinsic;
|
||||
@@ -2744,10 +2754,20 @@ void OBCameraNode::publishColoredPointCloud(const std::shared_ptr<ob::FrameSet>
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK_NOTNULL(pipeline_);
|
||||
if (!pipeline_) {
|
||||
RCLCPP_ERROR_STREAM(logger_, "pipeline is null in publishColoredPointCloud");
|
||||
return;
|
||||
}
|
||||
auto camera_params = pipeline_->getCameraParam();
|
||||
if (!device_) {
|
||||
RCLCPP_ERROR_STREAM(logger_, "device is null in publishColoredPointCloud");
|
||||
return;
|
||||
}
|
||||
auto device_info = device_->getDeviceInfo();
|
||||
CHECK_NOTNULL(device_info.get());
|
||||
if (!device_info || !device_info.get()) {
|
||||
RCLCPP_ERROR_STREAM(logger_, "device_info is null in publishColoredPointCloud");
|
||||
return;
|
||||
}
|
||||
auto pid = device_info->pid();
|
||||
if (depth_registration_ || pid == DABAI_MAX_PID) {
|
||||
camera_params.depthIntrinsic = camera_params.rgbIntrinsic;
|
||||
@@ -3464,8 +3484,15 @@ void OBCameraNode::onNewFrameCallback(const std::shared_ptr<ob::Frame> &frame,
|
||||
int height = static_cast<int>(video_frame->getHeight());
|
||||
auto frame_timestamp = getFrameTimestampUs(frame);
|
||||
auto timestamp = fromUsToROSTime(frame_timestamp);
|
||||
if (!device_) {
|
||||
RCLCPP_ERROR_STREAM(logger_, "device is null in onNewFrameCallback");
|
||||
return;
|
||||
}
|
||||
auto device_info = device_->getDeviceInfo();
|
||||
CHECK_NOTNULL(device_info);
|
||||
if (!device_info || !device_info.get()) {
|
||||
RCLCPP_ERROR_STREAM(logger_, "device_info is null in onNewFrameCallback");
|
||||
return;
|
||||
}
|
||||
auto pid = device_info->getPid();
|
||||
OBCameraIntrinsic intrinsic;
|
||||
OBCameraDistortion distortion;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <filesystem>
|
||||
#include <atomic>
|
||||
|
||||
#include <fstream>
|
||||
#include <iomanip> // For std::put_time
|
||||
@@ -35,6 +36,13 @@ std::string g_camera_name = "orbbec_camera"; // Assuming this is declared elsew
|
||||
std::string g_time_domain = "global"; // Assuming this is declared elsewhere
|
||||
|
||||
void signalHandler(int sig) {
|
||||
// Prevent recursive signal handling
|
||||
static std::atomic<bool> in_signal_handler{false};
|
||||
if (in_signal_handler.exchange(true)) {
|
||||
// Already in signal handler, force exit immediately
|
||||
_exit(sig);
|
||||
}
|
||||
|
||||
std::cout << "Received signal: " << sig << std::endl;
|
||||
if (sig == SIGINT || sig == SIGTERM) {
|
||||
static int signal_count = 0;
|
||||
@@ -47,8 +55,9 @@ void signalHandler(int sig) {
|
||||
} else if (signal_count >= 5) {
|
||||
// Force exit after second signal
|
||||
std::cout << "Force exit due to multiple signals" << std::endl;
|
||||
exit(sig);
|
||||
_exit(sig);
|
||||
}
|
||||
in_signal_handler.store(false);
|
||||
} else {
|
||||
std::string log_dir = "Log/";
|
||||
|
||||
@@ -81,7 +90,7 @@ void signalHandler(int sig) {
|
||||
}
|
||||
|
||||
log_file.close();
|
||||
exit(sig); // Exit program
|
||||
_exit(sig); // Use _exit instead of exit to avoid cleanup that may crash
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user