很不明白JNI里面获取指针的顺序(可能这样描述不太恰当吧)。
下面按照传入指针的顺序的代码一跑就崩溃。如下:
1 JNIEXPORT jint JNICALL Java_com_example_X_XX_XXX 2 (JNIEnv * env, jclass, jbyteArray databuf, jint width, jint height, jstring path, jintArray x1) 3 { 4 jboolean* pArraydata = (jboolean*)env->GetPrimitiveArrayCritical(databuf, 0); 5 char* pApath=env->GetStringUTFChars(path,0); 6 jint* pAx1 = (jint*)env->GetPrimitiveArrayCritical(x1, 0); 7 8 // code; 9 10 env->ReleasePrimitiveArrayCritical(databuf, pArraydata, 0); 11 env->ReleaseStringUTFChars(path, pApath); 12 env->ReleasePrimitiveArrayCritical(x1, pAx1, 0); 13 14 return eyedist; 15 }
之后将获取指针的顺序稍微修改了一下,然后就可以跑过去了。如下:
1 JNIEXPORT jint JNICALL Java_com_example_X_XX_XXX 2 (JNIEnv * env, jclass, jbyteArray databuf, jint width, jint height, jstring path, jintArray x1) 3 { 4 jboolean* pArraydata = (jboolean*)env->GetPrimitiveArrayCritical(databuf, 0); 5 jint* pAx1 = (jint*)env->GetPrimitiveArrayCritical(x1, 0); 6 char* pApath=env->GetStringUTFChars(path,0); 7 8 // code; 9 10 env->ReleasePrimitiveArrayCritical(databuf, pArraydata, 0); 11 env->ReleasePrimitiveArrayCritical(x1, pAx1, 0); 12 env->ReleaseStringUTFChars(path, pApath); 13 14 return eyedist; 15 }
时间: 2024-10-13 10:04:08