Guest User

JNI ReleaseByteArrayElements

a guest
Aug 2nd, 2011
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. LOGD("Size of image: %d", data->byteCount);
  2. jbyteArray imageBuf = p_env->NewByteArray(data->byteCount);
  3. p_env->SetByteArrayRegion(imageBuf, 0, data->byteCount, (jbyte*)data->buffer); (data->buffer contains byte[])
  4. jobject imageHashmap = jni_helpers_HashMap_create(p_env); // creates HashMap using NewObject
  5. jstring key = p_env->NewStringUTF("data");
  6. jni_helpers_HashMap_put(p_env, imageHashmap, key, imageBuf); // call put method on a HashMap instance
  7. p_env->DeleteLocalRef(key);
  8. key = p_env->NewStringUTF("width");
  9. jobject intVal = jni_helpers_create_Integer(p_env, data->width);
  10. jni_helpers_HashMap_put(p_env, imageHashmap, key, intVal);
  11. p_env->DeleteLocalRef(key);
  12. p_env->DeleteLocalRef(intVal);
  13. key = p_env->NewStringUTF("height");
  14. intVal = jni_helpers_create_Integer(p_env, data->height);
  15. jni_helpers_HashMap_put(p_env, imageHashmap, key, intVal);
  16. p_env->DeleteLocalRef(intVal);
  17. p_env->DeleteLocalRef(key);
  18. p_env->CallVoidMethod(g_callbackTarget, g_callbackMethod, EVENT_ID, (jobject)imageHashmap);
  19. LOGD("Cleaning up resources...");
  20. p_env->ReleaseByteArrayElements(imageBuf, (jbyte*)data->buffer, JNI_ABORT); // <!-- this is where I get the message
  21. p_env->DeleteLocalRef(imageBuf);
  22. p_env->DeleteLocalRef(imageHashmap);
Advertisement
Add Comment
Please, Sign In to add comment