1

I am calling a JNI function with int values as parameters. I am sending width and height as 800 and 480. But when I try to print these values in the JNI function I am getting 1 and 0 instead of 800 and 480. Why I am getting wrong values in JNI?

My JNI function call is:

findSquare(sourceImage.getNativeObjAddr(),
                        imageTaken.getNativeObjAddr(), 1, width, height);

public native void findSquare(long matAddrRgba, long matAddrDescriptor,
        int draw, int width, int height);

And the JNI function is:

JNIEXPORT jint JNICALL 
Java_info_androidhive_androidcameraapi_CameraMainActivity_findSquare(
        JNIEnv*, jobject, jlong addrRgba, jlong addrDescriptor, jlong addrSrc,
        jlong addrDst, jint draw, jint width, jint height);
4
  • 1
    Hi there !! You seem to be around for quite long time. Please take care of the formatting of the post yourself. Thank you. :-) Commented Mar 31, 2015 at 9:52
  • 3
    It seems like arguments in prototype and call function doesn't match. What happened with addrSrc and addrDst? Commented Mar 31, 2015 at 9:54
  • 1
    They are not matching. You have (long, long, int, int, int) on the Java side and (jlong, jlong, jlong, jint, jint, jint) on the JNI side. Reconcile this. Commented Mar 31, 2015 at 10:14
  • Actually it's even worse than that. You have five parameters in Java and seven in JNI, not counting the JNIEnv* and the jobject. Commented Mar 31, 2015 at 11:47

1 Answer 1

4

The android and native method signatures don't match.

Your Java native method should look like this:

// added addrSrc, addrDst which were missing.
public native void findSquare(long matAddrRgba, long matAddrDescriptor, 
                              long addrSrc, long addrDst, int draw, int width, 
                              int height);
Sign up to request clarification or add additional context in comments.

2 Comments

Iam getting Fatal signal 11 (SIGSEGV) at 0x00000004 (code=1) exception while calling native method? Could you please help me?
This exception will arise if we try to use a vector of size 0(in my case). I've missed 'length(>0)' check while using it with for loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.