Last active
August 25, 2022 15:12
-
-
Save vrunoa/a79deaf21231c601a1c056f2b7b003fd to your computer and use it in GitHub Desktop.
Convertng char* to jbyteArray the right way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
I guess at line 7 it should be env->SetByteArrayRegion(arr, 0, len, reinterpret_cast<jbyte*>(&frame));
@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
hi thanks, will help!