From f14a9467cb99bcd9c67b58285cf3cdd5efe4a864 Mon Sep 17 00:00:00 2001 From: hexbabe Date: Thu, 20 Jun 2024 12:05:49 -0400 Subject: [PATCH] Make color frame cast to video frame more safe --- src/encoding.hpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/encoding.hpp b/src/encoding.hpp index 6cebabc..15af983 100644 --- a/src/encoding.hpp +++ b/src/encoding.hpp @@ -296,10 +296,18 @@ std::vector rsPointsToPCDBytes(const rs2::points& points, const r if (hasColor && colorFrame) { colorData = static_cast(colorFrame.get_data()); - width = colorFrame.as().get_width(); - height = colorFrame.as().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(&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") } }