调试断言失败
Posted
技术标签:
【中文标题】调试断言失败【英文标题】:Debug Assertion Failes 【发布时间】:2014-03-05 12:10:59 【问题描述】:我正在使用集成在 Visual Studio 2010 中的 OpenCv 编写 C++ 代码。 我正在关注本教程:
http://opencv-srf.blogspot.com/2013/06/load-display-image.html
但是当我运行代码时,我得到了这个错误信息:
程序:...cuments\visual studio 2010\Projects\test1\x64\Debug\test1.exe 文件:f:\dd\vctools\crt_bld\self_64_amd64\crt\src\fopen.c 线路:54
表达式:(文件!= NULL)
有关您的程序如何导致断言的信息 失败,请参阅有关断言的 Visual C++ 文档。
这是我的代码:
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
Mat im = imread("C:/Users/Ruaa/Pictures/aa.png");
if (im.empty())
cout << "Cannot load image!" << endl;
return -1;
imshow("Image", im);
waitKey(0);
'test1.exe': Loaded 'C:\Users\Ruaa\Documents\Visual Studio 2010\Projects\test1\x64\Debug\test1.exe', Symbols loaded.
'test1.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'test1.exe': Loaded 'C:\Windows\System32\kernel32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\opencv1\opencv\build\x64\vc11\bin\opencv_core245d.dll', Cannot find or open the PDB file
'test1.exe': Loaded 'C:\Windows\System32\msvcp110d.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\msvcr110d.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\opencv1\opencv\build\x64\vc11\bin\opencv_highgui245d.dll', Cannot find or open the PDB file
'test1.exe': Loaded 'C:\Windows\System32\user32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\gdi32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\lpk.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\usp10.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\ole32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\advapi32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\sechost.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\winsxs\amd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7600.16661_none_a44e1fc257f685f6\comctl32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\msvfw32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\winmm.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\shell32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\avifil32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\msacm32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\avicap32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\version.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\msvcr100.dll', Symbols loaded.
'test1.exe': Loaded 'C:\Windows\System32\msvcp100.dll', Symbols loaded.
'test1.exe': Loaded 'C:\Windows\System32\imm32.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\msctf.dll', Symbols loaded (source information stripped).
Debug Assertion Failed!
Program: ...cuments\visual studio 2010\Projects\test1\x64\Debug\test1.exe
File: f:\dd\vctools\crt_bld\self_64_amd64\crt\src\fopen.c
Line: 54
Expression: (file != NULL)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
'test1.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Symbols loaded.
'test1.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Symbols loaded (source information stripped).
'test1.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Symbols loaded (source information stripped).
The program '[4984] test1.exe: Native' has exited with code 3 (0x3).
这是调用堆栈:
msvcr110d.dll!fopen() + 0x23 bytes
opencv_highgui245d.dll!000007feea737ea8()
[Frames below may be incorrect and/or missing, no symbols loaded for opencv_highgui245d.dll]
opencv_highgui245d.dll!000007feea73a725()
opencv_highgui245d.dll!000007feea73a5f1()
> test1.exe!main() Line 10 + 0x3d bytes C++
test1.exe!__tmainCRTStartup() Line 555 + 0x19 bytes C
kernel32.dll!BaseThreadInitThunk() + 0xd bytes
ntdll.dll!0000000077752ca1()
【问题讨论】:
@MichaelWalz 检查更新:) 那不是调用栈。 @MichaelWalz 我找不到它,我使用的是 Visual Studio 2010 Professional 要查看调用堆栈,请执行以下操作:使用调试器运行您的程序(调试->开始调试)。一旦它命中断言,执行 Debug->Windows->Call Stack。 如果你点击“重试”按钮,一旦遇到了断言,会发生什么?然后您应该能够看到调用堆栈。 【参考方案1】:这里有两个问题:
-
您的文件
C:/Users/Ruaa/Pictures/aa.png
不存在,您应该尝试使用现有文件
你用的是调试版的OpenCV的库,去掉.lib
/.dll
文件末尾的d
,比如opencv_highgui245d
=>opencv_highgui245
,这样会阻止断言,让它更快,而且你很少需要调试inside OpenCV
【讨论】:
仍然很奇怪它断言如果文件不存在。imread
带有不存在的文件应该返回一些错误代码或其他任何内容,但不会在 OpenCV 库中深入断言。
是的,肯定发生了一些可疑的事情,但很难说是什么!由 OpenCV 传递给 fopen
的字符串是错误的/null 还是 MSVC 的 fopen
在调试模式下过于严格?以上是关于调试断言失败的主要内容,如果未能解决你的问题,请参考以下文章