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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user