fix: Fix Unable to retrieve jni environment. Is the thread attached? errors by using jni::ThreadScope (#2457)

fix: Add `jni::ThreadScope` to `JVisionCameraScheduler`
This commit is contained in:
Marc Rousavy 2024-01-30 15:39:33 +01:00 committed by GitHub
parent 9089014ed8
commit 33e2adcec6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,7 +21,9 @@ void JVisionCameraScheduler::dispatchAsync(const std::function<void()>& job) {
}
void JVisionCameraScheduler::scheduleTrigger() {
// 2. schedule `triggerUI` to be called on the java thread
// 2.1 Open a JNI Thread scope because this might be called from a C++ background Thread
jni::ThreadScope scope;
// 2.2 schedule `triggerUI` to be called on the java thread
static auto method = _javaPart->getClass()->getMethod<void()>("scheduleTrigger");
method(_javaPart.get());
}