robovm icon indicating copy to clipboard operation
robovm copied to clipboard

MobiVM (2.3.14) crash when cloning direct ByteBuffer

Open muratmat opened this issue 3 years ago • 3 comments

Hello guys, I have a problem with MobiVM (2.3.14).

My JNI nativeMethod

return = (*env)->NewDirectByteBuffer(env, mallocedMemory, mallocedMemorySize);

Java code

ByteBuffer nativeData = jniNativeMethod();
ByteBuffer clonedData = ByteBuffer.allocateDirect(nativeData.capacity());

At this point buffers have the following information:

nativeData: capacity=1400, limit=1400, position=0, offset=0, mark=-1, mapMode=null, block=java.nio.MemoryBlock$UnmanagedBlock[<memAdrr0>]
clonedData: capacity=1400, limit=1400, position=0, offset=0, mark=-1, mapMode=null, block=java.nio.MemoryBlock$NonMovableHeapBlock[<memAdrr1>]

Java code (copy nativeData into clonedData)

clonedData.put(nativeData);

At this point buffers have the following information:

nativeData: capacity=1400, limit=1400, position=1400, offset=0, mark=-1, mapMode=null, block=java.nio.MemoryBlock$UnmanagedBlock[<memAdrr0>]
clonedData: capacity=1400, limit=1400, position=1400, offset=0, mark=-1, mapMode=null, block=java.nio.MemoryBlock$NonMovableHeapBlock[<memAdrr1>]

Because I want to read data from clonedData, I have to rewind such buffer, but a call to clonedData.position(0) or clonedData.rewind() crashes the application/MobiVM without any additional information nor a stack trace.

Any idea on the cause? The crash has been verified on a iPad Air (iOS 12.5.4) and on iPhone 8 Plus (iOS 14.7.1), XCode 12.5.1 (12E507) NB: the same code works fine on Android.

Many thanks in advance.

muratmat avatar Sep 01 '21 10:09 muratmat

Try adding a cast. Have a look at https://github.com/libgdx/libgdx/pull/6331

On Wed, 1 Sep 2021 at 12:23, Matteo Muratori @.***> wrote:

Hello guys, I have a problem with MobiVM (2.3.14).

My JNI nativeMethod

return = (*env)->NewDirectByteBuffer(env, mallocedMemory, mallocedMemorySize);

Java code

ByteBuffer nativeData = jniNativeMethod(); ByteBuffer clonedData = ByteBuffer.allocateDirect(nativeData.capacity());

At this point buffers have the following information:

nativeData: capacity=1400, limit=1400, position=0, offset=0, mark=-1, mapMode=null, block=java.nio.MemoryBlock$UnmanagedBlock[<memAdrr0>] clonedData: capacity=1400, limit=1400, position=0, offset=0, mark=-1, mapMode=null, block=java.nio.MemoryBlock$NonMovableHeapBlock[<memAdrr1>]

Java code (copy nativeData into clonedData)

clonedData.put(nativeData);

At this point buffers have the following information:

nativeData: capacity=1400, limit=1400, position=1400, offset=0, mark=-1, mapMode=null, block=java.nio.MemoryBlock$UnmanagedBlock[<memAdrr0>] clonedData: capacity=1400, limit=1400, position=1400, offset=0, mark=-1, mapMode=null, block=java.nio.MemoryBlock$NonMovableHeapBlock[<memAdrr1>]

Because I want to read data from clonedData, I have to rewind such buffer, but a call to clonedData.position(0) or clonedData.rewind() crashes the application/MobiVM without any additional information nor a stack trace.

Any idea on the cause? The crash has been verified on a iPad Air (iOS 12.5.4) and on iPhone 8 Plus (iOS 14.7.1), XCode 12.5.1 (12E507) NB: the same code works fine on Android.

Many thanks in advance.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/MobiVM/robovm/issues/595, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANWDPHSJNFII4SL3POLCKLT7X5JHANCNFSM5DGEOXEQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

obigu avatar Sep 01 '21 10:09 obigu

Thanks, a previous cast to Buffer solved the issue! Thanks again.

muratmat avatar Sep 01 '21 13:09 muratmat

also https://github.com/MobiVM/robovm/pull/615 addresses this case (probably issue might be closed)

dkimitsa avatar Feb 02 '22 13:02 dkimitsa

and finally solved with https://github.com/MobiVM/robovm/pull/728

dkimitsa avatar Jul 07 '23 09:07 dkimitsa