Don't crash if libcamera fails to load (#2498)

This commit is contained in:
Alan Everett
2026-05-19 23:42:09 -04:00
committed by GitHub
parent 645ff41ce9
commit c146d559d0
2 changed files with 16 additions and 5 deletions

View File

@@ -63,7 +63,14 @@ public class LibcameraGpuSettables extends VisionSourceSettables {
videoModes = new HashMap<>();
sensorModel = LibCameraJNI.getSensorModel(configuration.matchedCameraInfo.path());
LibCameraJNI.SensorModel tempSensorModel;
try {
tempSensorModel = LibCameraJNI.getSensorModel(configuration.matchedCameraInfo.path());
} catch (UnsatisfiedLinkError e) {
logger.error("Unable to load libcamera JNI", e);
tempSensorModel = LibCameraJNI.SensorModel.Disconnected;
}
sensorModel = tempSensorModel;
if (sensorModel == LibCameraJNI.SensorModel.IMX219) {
// Settings for the IMX219 sensor, which is used on the Pi Camera Module v2

View File

@@ -146,11 +146,15 @@ public class LibcameraGpuFrameProvider extends FrameProvider {
@Override
public boolean checkCameraConnected() {
String[] cameraNames = LibCameraJNI.getCameraNames();
for (String name : cameraNames) {
if (name.equals(settables.getConfiguration().getDevicePath())) {
return true;
try {
String[] cameraNames = LibCameraJNI.getCameraNames();
for (String name : cameraNames) {
if (name.equals(settables.getConfiguration().getDevicePath())) {
return true;
}
}
} catch (UnsatisfiedLinkError e) {
// libcamera failed to load; ignored
}
return false;
}