我正在用C++开发图像处理应用程序。我已经看到很多编译器错误和回溯,但是这对我来说是新的。
#0 0xb80c5430 in __kernel_vsyscall ()
#1 0xb7d1b6d0 in raise () from /lib/tls/i686/cmov/libc.so.6
#2 0xb7d1d098 in abort () from /lib/tls/i686/cmov/libc.so.6
#3 0xb7d5924d in ?? () from /lib/tls/i686/cmov/libc.so.6
#4 0xb7d62276 in ?? () from /lib/tls/i686/cmov/libc.so.6
#5 0xb7d639c5 in malloc () from /lib/tls/i686/cmov/libc.so.6
#6 0xb7f42f47 in operator new () from /usr/lib/libstdc++.so.6
#7 0x0805bd20 in Image<Color>::fft (this=0xb467640) at ../image_processing/image.cpp:545
这里发生了什么事?新运算符(operator)崩溃了,确定。但为什么?这不是内存不足(它尝试分配大约128Kb,一个128x64像素,每个像素有两个浮点数)。而且,它不会接缝,因为这是我自己的代码中的错误(构造函数不会被触碰!)。
提到的行(#7)中的代码是:
Image<Complex> *result = new Image<Complex>(this->resX, resY);
// this->resX = 128, resY = 64 (both int), Complex is a typedef for std::complex<float>
几乎相同的实例化可以在我的代码的其他地方使用。如果我注释掉这部分代码,则稍后将在类似的部分崩溃。我不明白,我也没有任何想法,如何调试它。有什么帮助吗?
编译器是gcc 4.3.3,libc是2.9(均来自Ubuntu Jaunty)
更新:
在相同的方法和main()中,我在错误行的上方添加了以下几行
Image<Complex> *test = new Image<Complex>(128, 64);
delete test;
奇怪的是:在同一方法中,它将崩溃,在main()中,它将不会崩溃。正如我提到的,Complex是std::complex 的typedef。构造函数不会被调用,我在该行之前和构造函数本身中插入了一个cout。
更新2:
感谢KPexEA提供的提示!我尝试了这个:
Image<Complex> *test = new Image<Complex>(128, 64);
delete test;
kiss_fft_cpx *output = (kiss_fft_cpx*) malloc( this->resX * this->resY/2 * sizeof(kiss_fft_cpx) );
kiss_fftndr( cfg, input, output );
Image<Complex> *test2 = new Image<Complex>(128, 64);
delete test2;
它崩溃了-您猜吗? -test2!因此,我的kissfft接缝的malloc就是有问题的。我来看一下。
最后更新:
好的,完成了!感谢大家!
实际上,我之前应该已经注意到它。上周,我注意到,kissfft(快速傅立叶变换库)从128x128像素的源图像制作了130x64像素的fft图像。是的,宽130像素,而不是128像素。不要问我为什么,我不知道!因此,必须分配130x64x2xsizeof(float)字节,而不是像我以前想象的那样分配128x64x...。奇怪的是,在我修复该错误后并没有崩溃,但是几天后。
记录下来,我的最终代码是:
int resY = (int) ceil(this->resY/2);
kiss_fft_cpx *output = (kiss_fft_cpx*) malloc( (this->resX+2) * resY * sizeof(kiss_fft_cpx) );
kiss_fftndr( cfg, input, output );
Image<Complex> *result = new Image<Complex>(this->resX, resY);
谢谢!
疯狂
最佳答案
也许先前分配的内存块有缓冲区溢出,这会破坏堆?
关于c++ - 奇怪的回溯-错误在哪里?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1231433/