fix: Fix JNI crash in FrameHostObject dtor (#689)
This commit is contained in:
parent
e8a8e71a76
commit
4584d33921
@ -13,14 +13,14 @@ namespace vision {
|
|||||||
|
|
||||||
using namespace facebook;
|
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() {
|
FrameHostObject::~FrameHostObject() {
|
||||||
// Hermes' Garbage Collector (Hades GC) calls destructors on a separate Thread
|
// 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
|
// 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
|
// deallocating the `frame` HybridClass, because otherwise JNI cannot call the Java
|
||||||
// destroy() function.
|
// destroy() function.
|
||||||
jni::ThreadScope::WithClassLoader([=] { frame.reset(); });
|
jni::ThreadScope::WithClassLoader([&] { frame.reset(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<jsi::PropNameID> FrameHostObject::getPropertyNames(jsi::Runtime& rt) {
|
std::vector<jsi::PropNameID> FrameHostObject::getPropertyNames(jsi::Runtime& rt) {
|
||||||
|
@ -28,7 +28,7 @@ class JSI_EXPORT FrameHostObject : public jsi::HostObject {
|
|||||||
void close();
|
void close();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
jni::local_ref<JImageProxy> frame;
|
jni::global_ref<JImageProxy> frame;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static auto constexpr TAG = "VisionCamera";
|
static auto constexpr TAG = "VisionCamera";
|
||||||
|
Loading…
Reference in New Issue
Block a user