现在的位置: 首页 > 综合 > 正文

Fatal signal 11 (SIGSEGV)的问题

2013年10月22日 ⁄ 综合 ⁄ 共 1080字 ⁄ 字号 评论关闭
 
  分类:
android课题
新手搞起东西来果然很麻烦啊,面对陌生的东西,只有前进前进前进,没有退路,不由得感慨万千。。

上网上查Fatal signal 11 (SIGSEGV),直说是和内存有关,具体为什么真的不知道,而且是丈二的和尚摸不着头脑,除了这一句没有明显的提示了。我的程序时双库的调用,先上段代码吧,这都是赤裸裸的教训啊!!
int ThresholdProcess(BYTE Image[], BYTE ThresholdFlag[])
{
int i;
for(i = 0; i < ImageWidth*ImageHeight; i ++)
{
if(Image[i] > 40)
{
ThresholdFlag[i] = 255;
}
else
ThresholdFlag[i] = 0;
}
return 1;
}
从表面看来没有什么明显的错误,而且逻辑上都没有问题,数组越界就更使不肯能了,之前做的时候倒是碰到了数组越界的问题,但是这次绝对没有越界的事儿了。
灵机一动,不知怎地,就想到JNI接口中应该将传递进来的参数转换一下,否则无法赋值和调用,于是乎就试了下,一系列的GetArrayLength,GetIntArrayElements后,将可以操作的数组作为参数传递进了函数内,果然是这个问题,给自己鼓下掌吧,帅呆了。
JNI调用函数为:
JNIEXPORT jint JNICALL Java_com_example_myapplication_MainActivity_test(JNIEnv *env, jobject thiz, jintArray Image, jintArray ThresholdFlag)
{
jint i;
LOGE("here");
jint length = (*env)->GetArrayLength(env, Image);
jint temp[length], tempthreshold[length];
jint* arr = (*env)->GetIntArrayElements(env, Image, NULL);
jint* threshold = (*env)->GetIntArrayElements(env, ThresholdFlag, NULL);
for(i = 0; i < length; i++)
{
temp[i] = arr[i];
tempthreshold[i] = threshold[i];
}
ThresholdProcess(temp, tempthreshold);
(*env)->SetIntArrayRegion(env,ThresholdFlag,0,length,tempthreshold);
return 1;
}

抱歉!评论已关闭.