Fix OpenNI2 enumeration softlocking sensors #745
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the OpenNI2 driver the initialization function (after calling
OpenNI::initialize()
in the client application), the driver will go to DeviceDriver.cppDriver::initialize()
. This function has a loopfor int i = 0; i < freenect2.enumerateDevices(); i++) { ... }
. This loop will cause all Kinect 2 USB devices to be unreachable until Windows restart is performed on some Windows builds. This happens, for some reason, because the loop's end condition,freenect2.enumerateDevices()
, is called on every loop. Something in this seems to utterly break libusb / UsbDK. The fix is to do the enumeration only once and save the result. There is probably some bigger reason as to why this happens, but I wasn't able to debug libusb / UsbDK to figure out the real culprit.When the enumeration is done every loop, the program will freeze at the enumeration call until after about 3 minutes this is printed:
After this error happens, on attempting to use the sensor again with Protonect without OpenNI2, the device cannot be opened:
I tried using LIBUSB_DEBUG=3 (in the Windows env vars), but it didn't seem to do anything.
I've attempted unplugging the sensor, moving it in a different USB3 controller (I have 3 separate USB 3 controllers on my motherboard / external card) and manually disabling the sensor via Device Manager. None of these actions seem to free the device. Interestingly, if I unplug the sensor and attempt to use Protonect, the sensor is still found and the same error as above is printed. The only ways I've found to circumvent this problem are restarting Windows or uninstalling + reinstalling UsbDK runtime. Plugging in a new Kinect 2 device works, until the same problem happens for it.
I'm not seeing this when building with MSVC 2013 64-bit, while using MSVC 2010 64-bit seems to cause the problem. I'm on Windows 8.1. I haven't tested if this happens on OS X or Linux.