fix: De-allocate frame
HybridClass with JNI class loader if using Hermes (#455)
* De-allocate `frame` HybridClass with JNI class loader if using Hermes
See 1b3a0c2612
* Don't wrap in `#if FOR_HERMES`, other `jsi::Runtime`s might also run GC on another Thread.
* Use `jni::local_ref` for `FrameHostObject`
* Update JImageProxyHostObject.cpp
* Only run with JNI `ClassLoader` if ctor Thread ID != dtor Thread ID
* Upgrade reanimated to 2.3.0-beta.1 to fix JNI crash
* Remove `this_thread::get_id()`
* Update Podfile.lock
This commit is contained in:
@@ -140,8 +140,6 @@ void FrameProcessorRuntimeManager::installJSIBindings() {
|
||||
auto cameraView = findCameraViewById(static_cast<int>(viewTag));
|
||||
__android_log_write(ANDROID_LOG_INFO, TAG, "Found CameraView!");
|
||||
|
||||
// TODO: does this have to be called on the separate VisionCamera Frame Processor Thread?
|
||||
|
||||
// convert jsi::Function to a ShareableValue (can be shared across runtimes)
|
||||
__android_log_write(ANDROID_LOG_INFO, TAG, "Adapting Shareable value from function (conversion to worklet)...");
|
||||
auto worklet = reanimated::ShareableValue::adapt(runtime, arguments[1],
|
||||
|
@@ -4,11 +4,25 @@
|
||||
|
||||
#include "JImageProxyHostObject.h"
|
||||
#include <android/log.h>
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <jni.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace vision {
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
JImageProxyHostObject::JImageProxyHostObject(jni::alias_ref<JImageProxy::javaobject> image): frame(make_local(image)) { }
|
||||
|
||||
JImageProxyHostObject::~JImageProxyHostObject() {
|
||||
// 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(); });
|
||||
}
|
||||
|
||||
std::vector<jsi::PropNameID> JImageProxyHostObject::getPropertyNames(jsi::Runtime& rt) {
|
||||
std::vector<jsi::PropNameID> result;
|
||||
result.push_back(jsi::PropNameID::forUtf8(rt, std::string("toString")));
|
||||
|
@@ -18,7 +18,8 @@ using namespace facebook;
|
||||
|
||||
class JSI_EXPORT JImageProxyHostObject : public jsi::HostObject {
|
||||
public:
|
||||
explicit JImageProxyHostObject(jni::alias_ref<JImageProxy::javaobject> image): frame(image) {}
|
||||
explicit JImageProxyHostObject(jni::alias_ref<JImageProxy::javaobject> image);
|
||||
~JImageProxyHostObject();
|
||||
|
||||
public:
|
||||
jsi::Value get(jsi::Runtime &, const jsi::PropNameID &name) override;
|
||||
@@ -27,7 +28,7 @@ class JSI_EXPORT JImageProxyHostObject : public jsi::HostObject {
|
||||
void close();
|
||||
|
||||
public:
|
||||
jni::alias_ref<JImageProxy> frame;
|
||||
jni::local_ref<JImageProxy> frame;
|
||||
|
||||
private:
|
||||
static auto constexpr TAG = "VisionCamera";
|
||||
|
Reference in New Issue
Block a user