Skip to content

Commit

Permalink
Make color frame cast to video frame more safe
Browse files Browse the repository at this point in the history
  • Loading branch information
hexbabe committed Jun 20, 2024
1 parent b61535c commit f14a946
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/encoding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,18 @@ std::vector<unsigned char> rsPointsToPCDBytes(const rs2::points& points, const r

if (hasColor && colorFrame) {
colorData = static_cast<const uint8_t*>(colorFrame.get_data());
width = colorFrame.as<rs2::video_frame>().get_width();
height = colorFrame.as<rs2::video_frame>().get_height();
if (width <= 0 || height <= 0) {
throw std::runtime_error("Error processing point cloud: color frame dimensions must be positive non-zero values");
auto video_frame = dynamic_cast<const rs2::video_frame*>(&colorFrame);
if (video_frame) {
width = video_frame->get_width();
height = video_frame->get_height();
if (width <= 0 || height <= 0) {
std::string error_msg = "Error processing point cloud: color frame dimensions must be positive "
"non-zero values. Received dimensions: " + std::to_string(width) + "x" +
std::to_string(height);
throw std::runtime_error(error_msg);
}
} else {
throw std::runtime_error("Error processing point cloud: color frame incompatible as video frame")
}
}

Expand Down

0 comments on commit f14a946

Please sign in to comment.