CameraOrbbecSDK: catch ob::Error in init() instead of crashing

Device open can throw ob::Error (e.g. uvc_open access denied on macOS
without camera permission, or an unsupported stream config). The throw
was uncaught and aborted the whole process. Wrap the device-access body
of init() in a try/catch that logs the error and returns false so the
caller can handle the failure gracefully.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
matlabbe
2026-06-28 13:16:40 -07:00
co-authored by Claude Opus 4.8
parent 703dc3a380
commit 21b50306cf
+14
View File
@@ -220,6 +220,12 @@ bool CameraOrbbecSDK::init(const std::string & calibrationFolder, const std::str
#ifdef RTABMAP_ORBBEC_SDK #ifdef RTABMAP_ORBBEC_SDK
this->close(); this->close();
// The Orbbec SDK reports failures by throwing ob::Error (e.g. uvc_open
// access denied on macOS without camera permission, or unsupported config).
// Catch them here so init() logs the error and returns false instead of
// letting the exception propagate and abort the whole process.
try {
std::shared_ptr<ob::Device> device; std::shared_ptr<ob::Device> device;
ob::Context context; ob::Context context;
@@ -546,6 +552,14 @@ bool CameraOrbbecSDK::init(const std::string & calibrationFolder, const std::str
return false; return false;
} }
}
catch(const ob::Error & e)
{
UERROR("Failed to initialize Orbbec camera: %s", e.what());
this->close();
return false;
}
return true; return true;
#else #else
UERROR("CameraOrbbecSDK: RTAB-Map is not built with Orbbec SDK support!"); UERROR("CameraOrbbecSDK: RTAB-Map is not built with Orbbec SDK support!");