Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp wrapper locks up on destruction, or on init with 0 devices #223

Closed
kylemcdonald opened this issue May 2, 2011 · 1 comment
Closed
Milestone

Comments

@kylemcdonald
Copy link

i'm noticing that the threaded function in Freenect::operator()() seems to lock up at pthread_join when:

1 you have no devices plugged in
2 you are closing an app (and there are no devices left)

i'm not sure what the exact reason is for this, but i'm getting much more stable performance by wrapping it with these two lines:

if(m_devices.size() > 0) {
    if(freenect_process_events(m_ctx) < 0) throw std::runtime_error("Cannot process freenect events");
}
sleep(1);

it would be great if someone who understands threading better could look over this.

it seems like freenect_process_events doesn't return when there are no devices to check on. so the (m_devices.size() > 0) thing combined with the sleep(1) gives the thread enough time to make it likely that freenect_process_events isn't called unless there are some device(s) to process. but if this is the reason, there should probably be a mutex that is shared between createDevice, deleteDevice and wrapped around the call to freenect_process_events as well.

edit: that sleep(1) is actually a bad idea. it's also enough time for the depth and video callbacks not to get called if you have another thread (like your GL loop) trying to check if there's a new frame... hrm...

@piedar
Copy link
Contributor

piedar commented Jan 18, 2014

cd5de90 fixes the freeze on shutdown.
todo: init with 0 devices

@piedar piedar modified the milestones: v0.4.0, v0.3.1, v0.4.1 Feb 6, 2014
@piedar piedar modified the milestones: v0.4.0, v0.4.1 Feb 15, 2014
@piedar piedar closed this as completed in cfe9c49 Feb 15, 2014
yarikoptic added a commit to yarikoptic/libfreenect that referenced this issue Feb 14, 2015
libfreenect v0.4.0 Oracle

* tag 'v0.4.0':
  Update for v0.4.0
  All headers (including libfreenect.hpp) are installed to `$PREFIX/include/libfreenect/`. All libfreenect files have `#include "libfreenect.h"` rather than `#include <libfreenect.h>`.  This works during build and after installation all include files are in the same directory. Rename libfreenect-audio.h -> libfreenect_audio.h and libfreenect-registration.h -> libfreenect_registration.h.  This makes them consistent with other libraries.
  wrappers/cpp: Call freenect_process_events_timeout in loop to prevent freezes - fixes OpenKinect#223
  OpenNI2-FreenectDriver: Fix silly silly string bugs; improve logging Fix ebuild for filename change
  OpenNI2-FreenectDriver: Convert all printf and cout statements to log messages
  Invoke fwfetcher.py with python2 - fixes OpenKinect#370 Refine README.md
  Remove C99 syntax - fixes OpenKinect#369
  Shiny new README.md Beautify ebuild and add audio USE flag
  Read int from fgetc for EOF comparison - fixes OpenKinect#365
  Replaced missing variable - fixes OpenKinect#366
  Post-merge cleanup
  small changes to allow compile on windows / visual studio
  Removed memset() after free() causing sporadic crashes when unplugging devices
  Fix ebuild
  Supports loading audio fw from memory as well as disk. Supports tilt,accel and led for K4W and 1473 device. Adds keep alive for K4W and 1473. Signed-off-by: Theodore Watson theo@openframeworks.cc (ofTheo)
  This code sets the LED of a 1473 Kinect or K4W Kinect to red on startup. This seems to fix a known issue for OS X users where the device renumerates within a small time period and causes a freeze. Closes OpenKinect#340 and addresses OpenKinect#316. Signed-off-by: Theodore Watson <theo@openframeworks.cc> (ofTheo)
  Remove outdated ebuild
  Add manpages for fakenect and fakenect-record
  Prefix freenect- to the name of the installed demos
  Rename record binary of fakenect as fakenect-record
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants