Skip to content

Commit

Permalink
Merge pull request OpenKinect#266 from gebart/cpp
Browse files Browse the repository at this point in the history
C++ wrapper: ignore LIBUSB_ERROR_INTERRUPTED from freenect_process_events()

Reviewed-by: Benn Snyder <[email protected]>
  • Loading branch information
piedar committed Jul 16, 2013
2 parents 955af59 + 4743a6e commit 5b4cb1f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion wrappers/cpp/libfreenect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@

#include <libfreenect.h>
#include <stdexcept>
#include <sstream>
#include <map>
#include <pthread.h>
#include <libusb-1.0/libusb.h>

namespace Freenect {
class Noncopyable {
Expand Down Expand Up @@ -209,7 +211,20 @@ namespace Freenect {
// Do not call directly, thread runs here
void operator()() {
while(!m_stop) {
if(freenect_process_events(m_ctx) < 0) throw std::runtime_error("Cannot process freenect events");
int res = freenect_process_events(m_ctx);
if (res < 0)
{
// libusb signals an error has occurred
if (res == LIBUSB_ERROR_INTERRUPTED)
{
// This happens sometimes, it means that a system call in libusb was interrupted somehow (perhaps due to a signal)
// The simple solution seems to be just ignore it.
continue;
}
std::stringstream ss;
ss << "Cannot process freenect events (libusb error code: " << res << ")";
throw std::runtime_error(ss.str());
}
}
}
static void *pthread_callback(void *user_data) {
Expand Down

0 comments on commit 5b4cb1f

Please sign in to comment.