Skip to content

Instantly share code, notes, and snippets.

@vrunoa
Last active August 25, 2022 15:12
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrunoa/a79deaf21231c601a1c056f2b7b003fd to your computer and use it in GitHub Desktop.
Save vrunoa/a79deaf21231c601a1c056f2b7b003fd to your computer and use it in GitHub Desktop.
Convertng char* to jbyteArray the right way
JNIEXPORT jbyteArray JNICALL Java_com_urucas_test_getframes(JNIEnv* env, jobject thiz) {
__android_log_write(ANDROID_LOG_INFO, "Test", "getting frames");
char* frame;
int len;
processor->getFrames(&frame, &len);
jbyteArray arr = env->NewByteArray(len);
env->SetByteArrayRegion(arr, 0, len, reinterpret_cast<jbyte*>(&frame));
delete processor;
return arr;
}
Copy link

ghost commented Apr 30, 2018

hi thanks, will help!

@Sammers21
Copy link

I guess at line 7 it should be env->SetByteArrayRegion(arr, 0, len, reinterpret_cast<jbyte*>(&frame));

@HetDerwel
Copy link

HetDerwel commented Mar 5, 2021

@Sammers21 well actually to be totally correct, it should be:
env->SetByteArrayRegion(arr, 0, len, reinterpret_cast<const jbyte*>(frame));
It frame is already the pointer that you want, so you don't want to be taking its address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment