android ndk - jint problem with NDK -


i'm trying make first native function ndk , i'm in trouble basic stuff.

please consider following c code:

#include <jni.h> #include <string.h>  jniexport jint jnicall java_eu_elevelcbt_sm_ycrcbutils_toargb(         jnienv* env, jbytearray src, jintarray out, jint width, jint height){       jbyte *c_src = (*env)->getbytearrayelements(env, src, null);     jint *c_out = (*env)->getdirectbufferaddress(env, out);      if (c_out==null)         return -1;      int length = width * height;     int co;     unsigned int color;      (co=0; co<length; co++) {         color = c_src[co] & 0xff;         color = 0xff000000 | (color<<16) | (color<<8) | color;         c_out[co] = color;     }      (*env)->releasebytearrayelements(env, src, c_src, 0);      return 0; }  jniexport jint jnicall java_eu_elevelcbt_sm_ycrcbutils_sum(jint a, jint b){     return a+b; } 

and following java class:

public class ycrcbutils {      public native int toargb(byte[] src, int[] out, final int width, final int height);      public native int sum(int a, int b);      static {         system.loadlibrary("yuv");     } } 

problem 1: if call second function

log.v("dbg", "sum is: " + new ycrcbutils().sum(10, 5)); 

this get: "sum 1079199776" !!!! why?!??!? :(

if try calling first function this:

int[] colors = new int[size.width * size.height]; // width=800 , height=480 new ycrcbutils().toargb(data, colors, size.width, size.height); // data byte[] 

i sigsegv error...

help please!!!

ps: dev environment mac osx snow leopard, ndk-r5b. runtime env nexus 1 2.3.3

...ok i'm stupid...

my methods signatures wrong... must have "jnienv* env, jobject obj" first 2 members... spend afternoon on thing i'll never forget it!

also, on first method had change

jint *c_out = (*env)->getdirectbufferaddress(env, out); 

with

jint *c_out = (*env)->getintarrayelements(env, out, null); 

as previous 1 returning null pointer


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -