Ankit Srivastava
Ankit Srivastava

Reputation: 12405

Reason for crash..?

I don't have much knowledge in C++ and I am using a file developed by someone else to apply autoLocalThresholding on my image.

here is how I am calling the method..

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

and here is the definition of these functions..

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);
}

now this gives me an EXEC_BAD_ACCESS error at this line..

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

can any one explain why is this happening and what is the remedy... ? the open source file is available here.. https://code.google.com/p/simple-iphone-image-processing/source/browse/trunk/Classes/Image.mm?r=15

AND also this happens sometimes not every time. Thanks in advance

Upvotes: 0

Views: 157

Answers (1)

KedarX
KedarX

Reputation: 781

The object newImage didn't get instantiated due to the issue with resize method as pointed out by OP.

Upvotes: 2

Related Questions