phil
unread,Aug 16, 2009, 11:13:13 AM8/16/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to android-ndk
I am trying to pass a bytebuffer to a jni method, and i can't seem to
get it to work --
Here's my java code --
byte[] buf1Bytes = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
ByteBuffer buf1 = ByteBuffer.wrap( buf1Bytes );
int buf1Len = buf1.capacity();
byte[] buf2Bytes = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
ByteBuffer buf2 = ByteBuffer.wrap( buf1Bytes );
int buf2Len = buf2Buf.capacity();
try {
ProcessBuffers(buf1, 0, buf1Len, buf2, 0, buf2en); // jni
call
} catch (Throwable t) {
System.out.println("t: " + t);
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf2Len; i++) {
sb.append(i + 1 + ": " + buf2.get(i));
sb.append("\n");
}
tv.setText( sb.toString() );
Here's my c code.
jint
Java_com_example_testjni_testJni_ProcessBuffer(JNIEnv* env, jobject
thiz, jobject buf1, jint buf1Off, jint buf1Len, jobject buf2Buf, jint
buf2Off, jint buf2Len)
{
int i;
int n;
jbyte* _buf1;
jbyte* _buf2;
_buf1 = (*env)->GetDirectBufferAddress(env, buf1);
_buf2 = (*env)->GetDirectBufferAddress(env, buf2);
n = buf2Len;
for (i = 0; i < n; i++) {
_buf2[i] = (_buf1[buf1Off + (i % buf1Len)] + 1) % 255;
}
}
The first thing it was doing was just completely dying when it tried
to make the call.
After I put a try/catch around it, I thought I would be able to set a
breakpoint in the catch, but it didn't trigger the breakpoint and it
wound up printing:
1: 0
2: 0
...
any ideas?
tia