Skip to content

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

@kylemcdonald

Description

@kylemcdonald

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions