fix: Fix close
being called on a collected reference (enforce alias_ref
) (#379)
* fix: Fix `close` being called on a collected reference (enforce `alias_ref`) * Remove `~FrameHostObject` on iOS too
This commit is contained in:
parent
97c20d96ae
commit
90f2a1ef7d
@ -34,9 +34,8 @@ void CameraView::frameProcessorCallback(const alias_ref<JImageProxy::javaobject>
|
||||
return;
|
||||
}
|
||||
|
||||
auto frameStrong = make_local(frame);
|
||||
try {
|
||||
frameProcessor_(frameStrong);
|
||||
frameProcessor_(frame);
|
||||
} catch (const std::exception& exception) {
|
||||
// TODO: jsi::JSErrors cannot be caught on Hermes. They crash the entire app.
|
||||
auto message = "Frame Processor threw an error! " + std::string(exception.what());
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace vision {
|
||||
|
||||
using namespace facebook;
|
||||
using FrameProcessor = std::function<void(jni::local_ref<JImageProxy::javaobject>)>;
|
||||
using FrameProcessor = std::function<void(jni::alias_ref<JImageProxy::javaobject>)>;
|
||||
|
||||
class CameraView : public jni::HybridClass<CameraView> {
|
||||
public:
|
||||
|
@ -155,7 +155,7 @@ void FrameProcessorRuntimeManager::installJSIBindings() {
|
||||
auto function = std::make_shared<jsi::Function>(worklet->getValue(rt).asObject(rt).asFunction(rt));
|
||||
|
||||
// assign lambda to frame processor
|
||||
cameraView->setFrameProcessor([this, &rt, function](jni::local_ref<JImageProxy::javaobject> frame) {
|
||||
cameraView->setFrameProcessor([this, &rt, function](jni::alias_ref<JImageProxy::javaobject> frame) {
|
||||
try {
|
||||
// create HostObject which holds the Frame (JImageProxy)
|
||||
auto hostObject = std::make_shared<JImageProxyHostObject>(frame);
|
||||
|
@ -77,15 +77,9 @@ void JImageProxyHostObject::assertIsFrameStrong(jsi::Runtime& runtime, const std
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JImageProxyHostObject::~JImageProxyHostObject() {
|
||||
this->close();
|
||||
}
|
||||
|
||||
void JImageProxyHostObject::close() {
|
||||
if (this->frame) {
|
||||
this->frame->close();
|
||||
this->frame.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,7 @@ using namespace facebook;
|
||||
|
||||
class JSI_EXPORT JImageProxyHostObject : public jsi::HostObject {
|
||||
public:
|
||||
explicit JImageProxyHostObject(jni::local_ref<JImageProxy::javaobject> image): frame(image) {}
|
||||
~JImageProxyHostObject();
|
||||
explicit JImageProxyHostObject(jni::alias_ref<JImageProxy::javaobject> image): frame(image) {}
|
||||
|
||||
public:
|
||||
jsi::Value get(jsi::Runtime &, const jsi::PropNameID &name) override;
|
||||
@ -28,7 +27,7 @@ class JSI_EXPORT JImageProxyHostObject : public jsi::HostObject {
|
||||
void close();
|
||||
|
||||
public:
|
||||
jni::local_ref<JImageProxy> frame;
|
||||
jni::alias_ref<JImageProxy> frame;
|
||||
|
||||
private:
|
||||
static auto constexpr TAG = "VisionCamera";
|
||||
|
@ -17,7 +17,6 @@ using namespace facebook;
|
||||
class JSI_EXPORT FrameHostObject: public jsi::HostObject {
|
||||
public:
|
||||
explicit FrameHostObject(Frame* frame): frame(frame) {}
|
||||
~FrameHostObject();
|
||||
|
||||
public:
|
||||
jsi::Value get(jsi::Runtime&, const jsi::PropNameID& name) override;
|
||||
|
@ -89,10 +89,6 @@ void FrameHostObject::assertIsFrameStrong(jsi::Runtime &runtime, const std::stri
|
||||
}
|
||||
}
|
||||
|
||||
FrameHostObject::~FrameHostObject() {
|
||||
close();
|
||||
}
|
||||
|
||||
void FrameHostObject::close() {
|
||||
if (frame != nil) {
|
||||
CMSampleBufferInvalidate(frame.buffer);
|
||||
|
Loading…
Reference in New Issue
Block a user