52 lines
1.9 KiB
Diff
52 lines
1.9 KiB
Diff
|
From db0e1825ff93133f3ca5735524d78279ede824db Mon Sep 17 00:00:00 2001
|
||
|
From: Rich Mattes <richmattes@gmail.com>
|
||
|
Date: Sat, 26 May 2018 16:14:01 -0400
|
||
|
Subject: [PATCH 2/2] Fix bugs in sync library error handling
|
||
|
|
||
|
fnusb_open_subdevices checked for camera==NULL or res < 0 before
|
||
|
jumping to the failure case. If camera was NULL but res was not
|
||
|
0, the function would return 0 indicating success. This occurs
|
||
|
when a kinect is not plugged into the PC. Forcing res to be
|
||
|
negative when the camera == NULL case allows the failure to open
|
||
|
a device to propagate through an application.
|
||
|
|
||
|
alloc_kinect in freenect_sync has a check for if freenect_open_device
|
||
|
fails, but the logic is incorrect. freenect_open_device returns 0 on
|
||
|
success and < 0 on error, so adding a check to see if the return is
|
||
|
< 0 corrects detection of the failure case.
|
||
|
|
||
|
Signed-off-by: Rich Mattes <richmattes@gmail.com>
|
||
|
---
|
||
|
src/usb_libusb10.c | 1 +
|
||
|
wrappers/c_sync/libfreenect_sync.c | 2 +-
|
||
|
2 files changed, 2 insertions(+), 1 deletion(-)
|
||
|
|
||
|
diff --git a/src/usb_libusb10.c b/src/usb_libusb10.c
|
||
|
index 11de86a..614aeee 100644
|
||
|
--- a/src/usb_libusb10.c
|
||
|
+++ b/src/usb_libusb10.c
|
||
|
@@ -465,6 +465,7 @@ FN_INTERNAL int fnusb_open_subdevices(freenect_device *dev, int index)
|
||
|
}
|
||
|
|
||
|
if (res < 0 || camera == NULL) {
|
||
|
+ res = -1;
|
||
|
goto failure;
|
||
|
}
|
||
|
|
||
|
diff --git a/wrappers/c_sync/libfreenect_sync.c b/wrappers/c_sync/libfreenect_sync.c
|
||
|
index 1b2e049..26a2261 100644
|
||
|
--- a/wrappers/c_sync/libfreenect_sync.c
|
||
|
+++ b/wrappers/c_sync/libfreenect_sync.c
|
||
|
@@ -249,7 +249,7 @@ static int change_depth_format(sync_kinect_t *kinect, freenect_resolution res, f
|
||
|
static sync_kinect_t *alloc_kinect(int index)
|
||
|
{
|
||
|
sync_kinect_t *kinect = (sync_kinect_t*)malloc(sizeof(sync_kinect_t));
|
||
|
- if (freenect_open_device(ctx, &kinect->dev, index)) {
|
||
|
+ if (freenect_open_device(ctx, &kinect->dev, index) < 0) {
|
||
|
free(kinect);
|
||
|
return NULL;
|
||
|
}
|
||
|
--
|
||
|
2.17.0
|
||
|
|