Hello,
I've tried looking at a bunch of forums, and despite a lot of tweaking and reanalyzing, I'm a little stuck.
I'm trying to return a jdoubleArray via the JNI from my C++ code, but the values I seem to be entering don't seem to be carrying through. Here's the code.
jdoubleArray ret = env->NewDoubleArray(2);
jdouble* rotationsJ = (jdouble *) malloc(2*sizeof(jdouble));
rotationsJ[0] = 4; //whatever, some dummy values.
rotationsJ[1] = 4;
cout<<"Rotations 0..."<<rotationsJ[0]; //Java console tells me this is 4, as it should.
env->SetDoubleArrayRegion(ret, 0, 2, (const jdouble*)rotationsJ);
return ret;
//EDIT - my java code looks like the following
double[] rotations = new double[2];
rotations = pnMain.rotateLeftRight(true); //PNMain is the calling class, rotateLeftRight returns a jDoubleArray.
//Was wondering if my Java declaration of rotations is needed?
Now in the Java code, the returned array from the C code is zeroed out. I can't seem to change it's values. I would think using the SetDoubleArrayRegion function would (hopefully) make the array 'ret' have the contents of rotationsJ, but this isn't working. I'm simply getting an array of two elements whose values are both 0.0 being passed back to me in Java.
Any help/questions is/are appreciated.
EDIT - I can add some more info to this. I tried doing:
jboolean isCopy;
jdouble* test = env->GetDoubleArrayElements(ret, &isCopy);
cout<<"Test ..."<<test[1]; //This actually printed out the second element's value in Java.
So the extra print statement I decided to try out - I copy over what I'm trying to return into another buffer in C, and just try printing it out. This actually reflects the value, while having been setup only using 'ret'. Could there be some problem in the return statement/in the Java code setup?