@@ -214,15 +214,18 @@ static void *init(void *unused)
214
214
return NULL ;
215
215
}
216
216
217
- static void init_thread (void )
217
+ static int init_thread (void )
218
218
{
219
219
thread_running = 1 ;
220
- freenect_init (& ctx , 0 );
220
+ int ret = freenect_init (& ctx , 0 );
221
+ if (ret != 0 ) return ret ;
221
222
// We claim both the motor and the camera, because we can't know in advance
222
223
// which devices the caller will want, and the c_sync interface doesn't
223
224
// support audio, so there's no reason to claim the device needlessly.
224
225
freenect_select_subdevices (ctx , (freenect_device_flags )(FREENECT_DEVICE_MOTOR | FREENECT_DEVICE_CAMERA ));
225
- pthread_create (& thread , NULL , init , NULL );
226
+ ret = pthread_create (& thread , NULL , init , NULL );
227
+ if (ret != 0 ) return ret ;
228
+ return 0 ;
226
229
}
227
230
228
231
static int change_video_format (sync_kinect_t * kinect , freenect_resolution res , freenect_video_format fmt )
@@ -279,8 +282,10 @@ static int setup_kinect(int index, int res, int fmt, int is_depth)
279
282
pending_runloop_tasks_inc ();
280
283
pthread_mutex_lock (& runloop_lock );
281
284
int thread_running_prev = thread_running ;
282
- if (!thread_running )
283
- init_thread ();
285
+ if (!thread_running ) {
286
+ int ret = init_thread ();
287
+ if (ret != 0 ) return ret ;
288
+ }
284
289
if (!kinects [index ]) {
285
290
kinects [index ] = alloc_kinect (index );
286
291
}
@@ -334,15 +339,15 @@ static int sync_get(void **data, uint32_t *timestamp, buffer_ring_t *buf)
334
339
}
335
340
336
341
337
- /*
342
+ /*
338
343
Use this to make sure the runloop is locked and no one is in it. Then you can
339
344
call arbitrary functions from libfreenect.h in a safe way. If the kinect with
340
- this index has not been initialized yet, then it will try to set it up. If
345
+ this index has not been initialized yet, then it will try to set it up. If
341
346
this function is successful, then you can access kinects[index]. Don't forget
342
347
to unlock the runloop when you're done.
343
-
348
+
344
349
Returns 0 if successful, nonzero if kinect[index] is unvailable
345
- */
350
+ */
346
351
static int runloop_enter (int index )
347
352
{
348
353
if (index < 0 || index >= MAX_KINECTS ) {
@@ -352,7 +357,7 @@ static int runloop_enter(int index)
352
357
if (!thread_running || !kinects [index ])
353
358
if (setup_kinect (index , FREENECT_RESOLUTION_MEDIUM , FREENECT_DEPTH_11BIT , 1 ))
354
359
return -1 ;
355
-
360
+
356
361
pending_runloop_tasks_inc ();
357
362
pthread_mutex_lock (& runloop_lock );
358
363
return 0 ;
@@ -407,7 +412,7 @@ int freenect_sync_get_tilt_state(freenect_raw_tilt_state **state, int index)
407
412
{
408
413
if (runloop_enter (index )) return -1 ;
409
414
freenect_update_tilt_state (kinects [index ]-> dev );
410
- * state = freenect_get_tilt_state (kinects [index ]-> dev );
415
+ * state = freenect_get_tilt_state (kinects [index ]-> dev );
411
416
runloop_exit ();
412
417
return 0 ;
413
418
}
0 commit comments