Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/protonect/include/libfreenect2/libfreenect2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ class LIBFREENECT2_API Freenect2
std::string getDeviceSerialNumber(int idx);
std::string getDefaultDeviceSerialNumber();

/* Important note:
* After passing a PacketPipeline object to libfreenect2 do not use or free the object,
* libfreenect2 will take care. If openDevice fails the PacketPipeline object will get
* deleted. A new PacketPipeline object has to be created each time a device is opened.
*/
Freenect2Device *openDevice(int idx);
Freenect2Device *openDevice(int idx, const PacketPipeline *factory);
Freenect2Device *openDevice(const std::string &serial);
Expand Down
8 changes: 6 additions & 2 deletions examples/protonect/src/libfreenect2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
if(idx >= num_devices)
{
std::cout << "[Freenect2Impl] requested device " << idx << " is not connected!" << std::endl;
delete pipeline;
return device;
}

Expand All @@ -688,6 +689,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
{
std::cout << "[Freenect2Impl] failed to get device " << PrintBusAndDevice(dev.dev)
<< " (the device may already be open)" << std::endl;
delete pipeline;
return device;
}

Expand All @@ -696,6 +698,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
if(r != LIBUSB_SUCCESS)
{
std::cout << "[Freenect2Impl] failed to open Kinect v2 " << PrintBusAndDevice(dev.dev) << "!" << std::endl;
delete pipeline;
return device;
}

Expand Down Expand Up @@ -733,6 +736,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
else if(r != LIBUSB_SUCCESS)
{
std::cout << "[Freenect2Impl] failed to reset Kinect v2 " << PrintBusAndDevice(dev.dev) << "!" << std::endl;
delete pipeline;
return device;
}
}
Expand Down Expand Up @@ -765,11 +769,11 @@ Freenect2Device *Freenect2::openDevice(const std::string &serial, const PacketPi
{
if(impl_->enumerated_devices_[idx].serial == serial)
{
device = openDevice(idx, pipeline);
break;
return openDevice(idx, pipeline);
}
}

delete pipeline;
return device;
}

Expand Down