崩溃的原因..
Reason for crash..?
本文关键字:崩溃 更新时间:2023-10-16
我对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
而且这种情况有时不会每次都发生。提前致谢
对象 newImage 由于 OP 指出的调整大小方法的问题而未实例化。
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 内联映射初始化的动态atexit析构函数崩溃
- 执行函数时导致崩溃的变量
- 程序崩溃并显示"std::out_of_range"错误
- CoInitialize()在单独的线程上崩溃而不返回
- 使用调试/崩溃报告将应用程序部署到客户端
- 为什么所有C++编译器都会崩溃或挂起此代码
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- 为什么我的多线程作业队列崩溃
- ExtractIconEx:可以工作,但偶尔会崩溃
- 为什么引用传递会导致此崩溃(C++)
- 试图创建流或fopen时程序崩溃
- 类对象数组的问题会导致崩溃
- 排序时无法执行交换操作.我做的时候它会崩溃.为什么
- 为什么要增加导致崩溃的指针
- 在虚幻引擎中删除NXOpen对象时崩溃
- 为什么它只打印双链接列表的第一个值,而我的程序却崩溃了
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- Visual Studio在尝试读取resource.txt文件时崩溃
- 将方法转换为调用该方法的成员函子对象会导致崩溃