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..3a22da2191 100644 --- a/src/win/win-helpers.cpp +++ b/src/win/win-helpers.cpp @@ -491,14 +491,16 @@ namespace librealsense } // Enumerate all imaging devices - for (int member_index = 0; ; ++member_index) + // 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 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;