OpenKinect / libfreenect

Drivers and libraries for the Xbox Kinect device on Windows, Linux, and OS X
http://openkinect.org
3.57k stars 1.15k forks source link

Kinect blocks on events (osx) #229

Closed fernLightning closed 12 years ago

fernLightning commented 13 years ago

Occurs on shutdown, freenect_process_events(), freenect_stop_depth(), freenect_stop_video(), or on shutdown if had iso errors during init....

Current solution so far (for osx), modified usb_libusb10.c

zarvox commented 13 years ago

Yes, we do need to add some proper handling of transfers that come back with some libusb error. Rather than accumulate a pile of workarounds, I'd like to rework the transfers to correctly handle the differences between failed, cancelled, and active transfers, at which point I'd expect this to all work properly.

And you're not alone: issue #227

fernLightning commented 12 years ago

Still locks up on device disconnect. The only solution I've found is to provide means to escape the while loop after a timeout. I'm unsure of the side effects of this, but it is working reliably for me.

int fnusb_stop_iso(fnusb_dev _dev, fnusb_isoc_stream *strm) { ... struct timeval start; gettimeofday(&start, NULL); while (strm->dead_xfers < strm->num_xfers) { struct timeval tv = {.tv_sec=1, .tv_usec=0}; // dont block forever, wait at most 1sec libusb_handle_events_timeout(ctx->usb.ctx, &tv); gettimeofday(&tv, NULL); long msecs = (tv.tv_sec - start.tv_sec)_1000; msecs += (tv.tv_usec - start.tv_usec)/1000; if(msecs > 4000) { FN_WARNING("Stopping - giving up after %ldms\n", msecs); break; } } ... }

zarvox commented 12 years ago

Hmm, so we cancel the transfers, but they never come back as dead? At first glance, that sounds like a libusb bug - we should be getting completed transfers with LIBUSB_TRANSFER_CANCELLED or LIBUSB_TRANSFER_NO_DEVICE.

I'll try to reproduce this - you say this happens to the demos on OSX when you unplug the Kinect?

fernLightning commented 12 years ago

It sometimes happens on disconnect, not always. It happens 1 out of 10 times here in the office with one kinect, but seems to happen far more often on site (where we have three kinects on the one machine).

I've not tried the Demos recently.

zarvox commented 12 years ago

The latest updates in unstable plus the one that adds freenect_process_events_timeout() should hopefully clear up the issues you noted.

In addition, we now return -1 from freenect_process_events if any of the underlying devices in the specified context have disappeared. The library knows which device vanished, but we're still trying to figure out a reasonably clean way to pass that up to the client.