From 4feb8b169b05e2379e3649ed257eb49e11f7a84f Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Mon, 23 Sep 2024 16:33:45 +0300 Subject: [PATCH 1/2] check sensors exist --- src/ds/d500/d500-color.cpp | 5 +++++ src/ds/d500/d500-device.cpp | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ds/d500/d500-color.cpp b/src/ds/d500/d500-color.cpp index 0d49268020..a9ccf23af8 100644 --- a/src/ds/d500/d500-color.cpp +++ b/src/ds/d500/d500-color.cpp @@ -63,6 +63,11 @@ namespace librealsense std::vector color_devs_info = filter_by_mi(group.uvc_devices, 3); + if ( color_devs_info.empty() ) + { + throw backend_exception("cannot access color sensor", RS2_EXCEPTION_TYPE_BACKEND); + } + std::unique_ptr< frame_timestamp_reader > ds_timestamp_reader_backup( new ds_timestamp_reader() ); std::unique_ptr ds_timestamp_reader_metadata(new ds_timestamp_reader_from_metadata(std::move(ds_timestamp_reader_backup))); diff --git a/src/ds/d500/d500-device.cpp b/src/ds/d500/d500-device.cpp index 9c38d0aeeb..faed9c8e7c 100644 --- a/src/ds/d500/d500-device.cpp +++ b/src/ds/d500/d500-device.cpp @@ -341,7 +341,14 @@ namespace librealsense using namespace ds; std::vector> depth_devices; - for( auto & info : filter_by_mi( all_device_infos, 0 ) ) // Filter just mi=0, DEPTH + auto depth_devs_info = filter_by_mi( all_device_infos, 0 ); + + if ( depth_devs_info.empty() ) + { + throw backend_exception("cannot access depth sensor", RS2_EXCEPTION_TYPE_BACKEND); + } + + for( auto & info : depth_devs_info ) // Filter just mi=0, DEPTH depth_devices.push_back( get_backend()->create_uvc_device( info ) ); std::unique_ptr< frame_timestamp_reader > timestamp_reader_backup( new ds_timestamp_reader() ); From 5da690ac11b77363cd9a6111ff43855d5c7621ba Mon Sep 17 00:00:00 2001 From: Nir Azkiel Date: Mon, 23 Sep 2024 19:12:21 +0300 Subject: [PATCH 2/2] prtect against missing color sensor d400 --- src/ds/d400/d400-device.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ds/d400/d400-device.cpp b/src/ds/d400/d400-device.cpp index 5dfc8232fc..184c51f2e4 100644 --- a/src/ds/d400/d400-device.cpp +++ b/src/ds/d400/d400-device.cpp @@ -478,7 +478,13 @@ namespace librealsense using namespace ds; std::vector> depth_devices; - for (auto&& info : filter_by_mi(all_device_infos, 0)) // Filter just mi=0, DEPTH + auto depth_devs_info = filter_by_mi( all_device_infos, 0 ); + + if ( depth_devs_info.empty() ) + { + throw backend_exception("cannot access depth sensor", RS2_EXCEPTION_TYPE_BACKEND); + } + for (auto&& info : depth_devs_info) // Filter just mi=0, DEPTH depth_devices.push_back( get_backend()->create_uvc_device( info ) ); std::unique_ptr< frame_timestamp_reader > timestamp_reader_backup( new ds_timestamp_reader() );