From 3b9251c8fae62cbb758269fd39c6fbb3efd0ea8f Mon Sep 17 00:00:00 2001 From: Remi Bettan Date: Wed, 18 Dec 2024 14:05:53 +0200 Subject: [PATCH 1/2] improvements to avoid crashes --- src/ds/d400/d400-device.cpp | 11 ++++++++--- src/ds/d500/d500-device.cpp | 12 ++++++++---- src/win/win-helpers.cpp | 9 +++++---- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/ds/d400/d400-device.cpp b/src/ds/d400/d400-device.cpp index fe61a97678..8a566e45f1 100644 --- a/src/ds/d400/d400-device.cpp +++ b/src/ds/d400/d400-device.cpp @@ -487,12 +487,17 @@ namespace librealsense std::vector> depth_devices; auto depth_devs_info = filter_by_mi( all_device_infos, 0 ); - if ( depth_devs_info.empty() ) + for (auto&& info : depth_devs_info) // Filter just mi=0, DEPTH + { + auto depth_uvc_device = get_backend()->create_uvc_device(info); + if (depth_uvc_device) + depth_devices.push_back(depth_uvc_device); + } + + if (depth_devs_info.empty() || depth_devices.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() ); frame_timestamp_reader* timestamp_reader_from_metadata; diff --git a/src/ds/d500/d500-device.cpp b/src/ds/d500/d500-device.cpp index e33c9b144c..3d78487694 100644 --- a/src/ds/d500/d500-device.cpp +++ b/src/ds/d500/d500-device.cpp @@ -359,13 +359,17 @@ namespace librealsense std::vector> depth_devices; auto depth_devs_info = filter_by_mi( all_device_infos, 0 ); - if ( depth_devs_info.empty() ) + for (auto&& info : depth_devs_info) // Filter just mi=0, DEPTH { - throw backend_exception("cannot access depth sensor", RS2_EXCEPTION_TYPE_BACKEND); + auto depth_uvc_device = get_backend()->create_uvc_device(info); + if (depth_uvc_device) + depth_devices.push_back(depth_uvc_device); } - for( auto & info : depth_devs_info ) // Filter just mi=0, DEPTH - depth_devices.push_back( get_backend()->create_uvc_device( info ) ); + if (depth_devs_info.empty() || depth_devices.empty()) + { + throw backend_exception("cannot access depth sensor", RS2_EXCEPTION_TYPE_BACKEND); + } std::unique_ptr< frame_timestamp_reader > timestamp_reader_backup( new ds_timestamp_reader() ); std::unique_ptr timestamp_reader_metadata(new ds_timestamp_reader_from_metadata(std::move(timestamp_reader_backup))); diff --git a/src/win/win-helpers.cpp b/src/win/win-helpers.cpp index 1c85a0d1f6..c95841118e 100644 --- a/src/win/win-helpers.cpp +++ b/src/win/win-helpers.cpp @@ -491,14 +491,15 @@ namespace librealsense } // Enumerate all imaging devices - for (int member_index = 0; ; ++member_index) + for (DWORD member_index = 0; member_index < 0x10000; ++member_index) { // Get device information element from the device information set if (SetupDiEnumDeviceInfo(device_info, member_index, &devInfo) == FALSE) { - if( GetLastError() == ERROR_NO_MORE_ITEMS ) - break; // stop when none left - continue; // silently ignore other errors + DWORD last_error = GetLastError(); + if ((last_error == ERROR_NO_MORE_ITEMS) || (last_error == ERROR_INVALID_HANDLE)) + break; // stop when none left + continue; // silently ignore other errors } } std::string parent_uid; From 8a14959cee56b061808668250df006837a951ad1 Mon Sep 17 00:00:00 2001 From: Remi Bettan Date: Sun, 22 Dec 2024 10:14:37 +0200 Subject: [PATCH 2/2] comment added --- src/win/win-helpers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win/win-helpers.cpp b/src/win/win-helpers.cpp index c95841118e..3a22da2191 100644 --- a/src/win/win-helpers.cpp +++ b/src/win/win-helpers.cpp @@ -491,6 +491,7 @@ namespace librealsense } // Enumerate all imaging devices + // high limit is below loop has been added to avoid infinite loop for (DWORD member_index = 0; member_index < 0x10000; ++member_index) { // Get device information element from the device information set