Skip to content

Commit

Permalink
improvements to avoids crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
remibettan committed Dec 18, 2024
1 parent 367937d commit 46c52e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
11 changes: 8 additions & 3 deletions src/ds/d400/d400-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,17 @@ namespace librealsense
std::vector<std::shared_ptr<platform::uvc_device>> 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;
Expand Down
12 changes: 8 additions & 4 deletions src/ds/d500/d500-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,17 @@ namespace librealsense
std::vector<std::shared_ptr<platform::uvc_device>> 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<frame_timestamp_reader> timestamp_reader_metadata(new ds_timestamp_reader_from_metadata(std::move(timestamp_reader_backup)));
Expand Down
11 changes: 6 additions & 5 deletions src/win/win-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,18 +491,19 @@ 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;
if( get_usb_device_descriptors( devInfo.DevInst, device_vid, device_pid, device_uid, location, spec, serial, parent_uid ) )
if (get_usb_device_descriptors( devInfo.DevInst, device_vid, device_pid, device_uid, location, spec, serial, parent_uid ) )
return true;
}
}
Expand Down

0 comments on commit 46c52e1

Please sign in to comment.