fix: Fix JNI crash in FrameHostObject dtor (#689)

This commit is contained in:
Janic Duplessis 2022-01-02 09:57:15 -05:00 committed by GitHub
parent e8a8e71a76
commit 4584d33921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -13,14 +13,14 @@ namespace vision {
using namespace facebook;
FrameHostObject::FrameHostObject(jni::alias_ref<JImageProxy::javaobject> image): frame(make_local(image)) { }
FrameHostObject::FrameHostObject(jni::alias_ref<JImageProxy::javaobject> image): frame(make_global(image)) { }
FrameHostObject::~FrameHostObject() {
// Hermes' Garbage Collector (Hades GC) calls destructors on a separate Thread
// which might not be attached to JNI. Ensure that we use the JNI class loader when
// deallocating the `frame` HybridClass, because otherwise JNI cannot call the Java
// destroy() function.
jni::ThreadScope::WithClassLoader([=] { frame.reset(); });
jni::ThreadScope::WithClassLoader([&] { frame.reset(); });
}
std::vector<jsi::PropNameID> FrameHostObject::getPropertyNames(jsi::Runtime& rt) {

View File

@ -28,7 +28,7 @@ class JSI_EXPORT FrameHostObject : public jsi::HostObject {
void close();
public:
jni::local_ref<JImageProxy> frame;
jni::global_ref<JImageProxy> frame;
private:
static auto constexpr TAG = "VisionCamera";