2012-05-29 77 views
0

我对C++没有多少知识,我正在使用其他人开发的文件在我的图像上应用autoLocalThresholding。崩溃的原因..?

这里是我如何打电话的方法..

UIImage *newImage = [imageProcessing resizeImage:image]; 
ImageWrapper *greyScale=Image::createImage(newImage, newImage.size.width, newImage.size.height); 
ImageWrapper *edges=greyScale.image->autoLocalThreshold(); 

,这里是这些函数的定义..

ImageWrapper* Image::autoLocalThreshold() { 
    const int local_size=8; 
    // now produce the thresholded image 
    uint8_t *result=(uint8_t*) malloc(m_width*m_height); 
    // get the initial total 
    int total=0; 
    for(int y=0; y<local_size; y++) { 
     for(int x=0; x<local_size; x++) { 
      total+=(*this)[y][x]; 
     } 
    } 
    // process the image 
    int lastIndex=m_width*m_height-(m_width*local_size/2+local_size/2); 
    for(int index=m_width*local_size/2+local_size/2; index<lastIndex; index++) { 
     int threshold=total/64; 
     if(m_imageData[index]>threshold*0.9) 
      result[index]=0; 
     else 
      result[index]=255; 
     // calculate the new total 
     for(int index2=index-m_width*local_size/2-local_size/2; index2<index+m_width*local_size/2-local_size/2; index2+=m_width) { 
      total-=m_imageData[index2]; 
      total+=m_imageData[index2+local_size]; 
     } 
    } 
    return Image::createImage(result, m_width, m_height, true); 
} 

现在这给了我一个EXEC_BAD_ACCESS错误在该行..

  total+=(*this)[y][x]; 

任何人都可以解释为什么会发生这种情况,补救措施是什么......? 开源文件可在此处获得。https://code.google.com/p/simple-iphone-image-processing/source/browse/trunk/Classes/Image.mm?r=15

而且这种情况有时并非每次都发生。 在此先感谢

+0

通常启用NSZombies有助于调试EXEC_BAD_ACCESS错误。你尝试过吗? – BBog

+0

是它已经启用,并导致我这条线“总+ =(* this)[y] [x]; ” –

+1

看你的图像对象没有实例化。 – KedarX

回答

2

对象newImage没有被实例化,因为由OP指出的调整大小方法的问题。