Skip to content

Commit 4743a6e

Browse files
author
Joakim Gebart
committed
C++ wrapper: ignore LIBUSB_ERROR_INTERRUPTED from freenect_process_events()
I kept getting errors about "Cannot process freenect events" when trying to start cppview although glview worked perfectly. It turns out libusb kept returning error "interrupted" when starting up, this patch ignores all such errors from libusb. I do not know libusb well enough to be able to tell whether this workaround will cause any problems in special cases. cppview seems to be working, but crashes when pressing ESC or closing the window with the error "pure virtual method called". I'm still investigating that error but I do not think it is related to this patch. Signed-off-by: Joakim Gebart <[email protected]>
1 parent e1365de commit 4743a6e

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)