fix: Fix HostObject destructors to make sure a JNI Environment is set up (#2462)

* fix: Fix HostObject destructors to make sure a JNI Environment is set up

* Use `reset` instead of `= nullptr`

* Format

* Format
This commit is contained in:
Marc Rousavy
2024-01-30 16:51:09 +01:00
committed by GitHub
parent 9e1297531e
commit 5f75b9e8dc
5 changed files with 21 additions and 9 deletions

View File

@@ -15,6 +15,9 @@ MutableJByteBuffer::MutableJByteBuffer(jni::alias_ref<jni::JByteBuffer> byteBuff
}
MutableJByteBuffer::~MutableJByteBuffer() noexcept {
// Hermes GC might destroy HostObjects on an arbitrary Thread which might not be
// connected to the JNI environment. To make sure fbjni can properly destroy
// the Java method, we connect to a JNI environment first.
jni::ThreadScope::WithClassLoader([&] { _byteBuffer.reset(); });
}
@@ -30,4 +33,4 @@ jni::global_ref<jni::JByteBuffer> MutableJByteBuffer::getByteBuffer() {
return _byteBuffer;
}
} // namespace vision
} // namespace vision