Skip to content

Commit 5b4cb1f

Browse files
committed
Merge pull request #266 from gebart/cpp
C++ wrapper: ignore LIBUSB_ERROR_INTERRUPTED from freenect_process_events() Reviewed-by: Benn Snyder <[email protected]>
2 parents 955af59 + 4743a6e commit 5b4cb1f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

wrappers/cpp/libfreenect.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828

2929
#include <libfreenect.h>
3030
#include <stdexcept>
31+
#include <sstream>
3132
#include <map>
3233
#include <pthread.h>
34+
#include <libusb-1.0/libusb.h>
3335

3436
namespace Freenect {
3537
class Noncopyable {
@@ -209,7 +211,20 @@ namespace Freenect {
209211
// Do not call directly, thread runs here
210212
void operator()() {
211213
while(!m_stop) {
212-
if(freenect_process_events(m_ctx) < 0) throw std::runtime_error("Cannot process freenect events");
214+
int res = freenect_process_events(m_ctx);
215+
if (res < 0)
216+
{
217+
// libusb signals an error has occurred
218+
if (res == LIBUSB_ERROR_INTERRUPTED)
219+
{
220+
// This happens sometimes, it means that a system call in libusb was interrupted somehow (perhaps due to a signal)
221+
// The simple solution seems to be just ignore it.
222+
continue;
223+
}
224+
std::stringstream ss;
225+
ss << "Cannot process freenect events (libusb error code: " << res << ")";
226+
throw std::runtime_error(ss.str());
227+
}
213228
}
214229
}
215230
static void *pthread_callback(void *user_data) {

0 commit comments

Comments
 (0)