Skip to content

Commit

Permalink
fix: Fix alias_ref being destroyed immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Sep 16, 2024
1 parent adde14a commit eb90b8d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ByteBufferArrayBuffer final : public ArrayBuffer {
}

public:
[[nodiscard]] jni::alias_ref<jni::JByteBuffer> getBuffer() const {
[[nodiscard]] const jni::global_ref<jni::JByteBuffer>& getBuffer() const {
return _byteBuffer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ class JArrayBuffer final : public jni::HybridClass<JArrayBuffer> {
* `ByteBuffer`. In this case, `getBuffer()` will **copy** the data into a new `ByteBuffer` if
* `copyIfNeeded` is `true`, and **wrap** the data into a new `ByteBuffer` if `copyIfNeeded` is false.
*/
jni::alias_ref<jni::JByteBuffer> getByteBuffer(bool copyIfNeeded) {
jni::local_ref<jni::JByteBuffer> getByteBuffer(bool copyIfNeeded) {
auto byteBufferArrayBuffer = std::dynamic_pointer_cast<ByteBufferArrayBuffer>(_arrayBuffer);
if (byteBufferArrayBuffer != nullptr) {
// It is a `ByteBufferArrayBuffer`, which has a `ByteBuffer` underneath!
return byteBufferArrayBuffer->getBuffer();
return jni::make_local(byteBufferArrayBuffer->getBuffer());
} else {
// It is a different kind of `ArrayBuffer`, we need to copy or wrap the data.
size_t size = _arrayBuffer->size();
Expand Down

0 comments on commit eb90b8d

Please sign in to comment.