I noticed that when unplugging and replugging the camera, and giving the autorization too fast, it made the application crash.
After debugging, I found that the vm->DetachCurrentThread() was called sometimes on a wrong thread, and I came up with this fix in the UVCStatusCallback.cpp on the uvc_status_callback method. I don't know if it is how it should be done, but it worked for me :
void UVCStatusCallback::uvc_status_callback(uvc_status_class status_class, int event, int selector, uvc_status_attribute status_attribute, void *data, size_t data_len, void *user_ptr) {
UVCStatusCallback *statusCallback = reinterpret_cast<UVCStatusCallback *>(user_ptr);
if (!statusCallback) return;
JavaVM *vm = getVM();
if (!vm) return;
JNIEnv *env = nullptr;
bool needsDetach = false;
int getEnvStat = vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6);
if (getEnvStat == JNI_EDETACHED) {
if (vm->AttachCurrentThread(&env, nullptr) != 0) {
LOGE("Failed to attach current thread");
return;
}
needsDetach = true;
} else if (getEnvStat == JNI_EVERSION) {
LOGE("GetEnv: version not supported");
return;
}
statusCallback->notifyStatusCallback(env, status_class, event, selector, status_attribute, data, data_len);
if (needsDetach) {
vm->DetachCurrentThread();
}
}
I noticed that when unplugging and replugging the camera, and giving the autorization too fast, it made the application crash.
After debugging, I found that the vm->DetachCurrentThread() was called sometimes on a wrong thread, and I came up with this fix in the UVCStatusCallback.cpp on the
uvc_status_callbackmethod. I don't know if it is how it should be done, but it worked for me :