OpenKinect / libfreenect

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

FreenectDriver Shouldn't Remove Device from devices() #593

Closed TroikaTronix closed 4 years ago

TroikaTronix commented 4 years ago

When closing an OpenNI Device using openni::Device::close(), the function deviceClose() in DeviceDriver.cp removes the device from the devices list. If you attempt to reopen the device using openni::Device::open() without reiniting OpenNI entirely, the call will erroneously fail because it says the device doesn't exist.

For situations where OpenNI is not a singleton, this is problematic becasue if you cannot reopen the device without calling the global function openni::OpenNI::shutdown() followed by openni::OpenNI::initialize() to rebuild the list of available devices.

Starting at line 307 of DeviceDriver.cpp is the following code

devices.erase(iter);
deleteDevice(id);

Since the actual device is deinstantiated by when deleteDevice(id) is called, you should simply set the the OpenNI driver pointer to NULL, and then go ahead and delete the device

iter->second = NULL;
deleteDevice(id);

This ensures that the entry for the device remains in the table and it will be found by a subsequent call to openni::Device::open()

piedar commented 4 years ago

:+1: good find