CameraOrbbecSDK: harden capture path against crashes

- Fix a format-string crash: the "unexpected frame count" warning used
  %s with a uint32_t, dereferencing the integer as a char*.
- Wrap captureImage() in try/catch(ob::Error) so a transient frame/USB
  error logs and skips the frame (empty SensorData) instead of aborting.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
matlabbe
2026-06-28 14:00:15 -07:00
co-authored by Claude Opus 4.8
parent 8d55ce44f6
commit e646b1cd79
+14 -1
View File
@@ -612,13 +612,19 @@ SensorData CameraOrbbecSDK::captureImage(SensorCaptureInfo * info)
UERROR("Camera is not initialized!");
return data;
}
// The streaming calls below can throw ob::Error (transient frame/USB
// errors, filter or profile failures). Catch them so a bad frame is logged
// and skipped (empty SensorData) instead of aborting the whole process.
try {
auto frameset = pipeline_->waitForFrameset();
if(frameset == nullptr || frameset->getCount() == 0) {
UWARN("No frame received!");
return data;
}
if(frameset->getCount() != 2) {
UWARN("Received %s frames, expecting 2!", frameset->getCount());
UWARN("Received %u frames, expecting 2!", frameset->getCount());
return data;
}
@@ -747,6 +753,13 @@ SensorData CameraOrbbecSDK::captureImage(SensorCaptureInfo * info)
}
}
}
catch(const ob::Error & e)
{
UERROR("Error capturing Orbbec camera frame: %s", e.what());
return data;
}
#else
UERROR("CameraOrbbecSDK: RTAB-Map is not built with Orbbec SDK support!");
#endif