我正在用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
這是怎麼回事?新操作員正在崩潰,好的。但爲什麼?這不是一個內存不足(它試圖分配約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的賈蒂)
更新:
我已經包括以下行的正上方在同一方法中的故障線路和在main()的
Image<Complex> *test = new Image<Complex>(128, 64);
delete test;
奇怪的:在同樣的方法就會死機,在main()不會。正如我所提到的,Complex是一個std :: complex <float>的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);
謝謝!
craesh
也許增加一個「幾乎相同」 – Amber 2009-08-05 06:03:49