C++ 调试断言失败:_CrtIsValidHeapPointer(pUserData)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10819550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debug Assertion Failed: _CrtIsValidHeapPointer(pUserData)
提问by Marco Carletti
SometimesI get this "Debug Assertion Failed" error running my Qt project in debug mode (image). I don't know where I wrong because the compiler says nothing and I don't know what to do to find my error.
有时我会在调试模式下运行我的 Qt 项目时遇到“调试断言失败”错误(图像)。我不知道我错在哪里,因为编译器什么也没说,我不知道该怎么做才能找到我的错误。
I program under Windows Vista, using Qt Creator 2.4.1, Qt 4.8.1.
我在 Windows Vista 下编程,使用 Qt Creator 2.4.1、Qt 4.8.1。
My program has to read some informations from a laser device and save them into a file with a code similar to this:
我的程序必须从激光设备读取一些信息并将它们保存到一个文件中,代码类似于:
void runFunction()
{
configure_Scanning(...);
while(...)
{
// do something
scanFunction();
// do something
}
}
and this is my "incriminated" function (where I think the problem is)
这是我的“有罪”功能(我认为问题出在哪里)
void scanFunction()
{
file.open();
data = getDataFromDevice();
if(flag)
{
if(QString::compare(lineB,"")!=0)
{
QTextStream out(&file);
out << lineB << endl;
lineB = "";
}
lineA.append(data+"\t");
}
else
{
if(QString::compare(lineA,"")!=0)
{
QTextStream out(&file);
out << lineA << endl;
lineA = "";
}
lineB.prepend(data+"\t");
}
file.close();
}
Where lineAand lineBare initially two void QString: the idea is that I make a bidirectional scanning to save informations in a 2D matrix (from -X to +X and viceversa, while Y goes to a specified target). lineAmemorizes the (-)to(+) reading; lineBmemorizes the (+)to(-) reading. When the scanning direction changes, I write lineA(or lineB) to the file and I proceed with the scanning.
其中lineA和lineB最初是两个 void QString:想法是我进行双向扫描以将信息保存在 2D 矩阵中(从 -X 到 +X,反之亦然,而 Y 则转到指定的目标)。lineA记住 (-) 到 (+) 的读数;lineB记住 (+) 到 (-) 读数。当扫描方向改变时,我将lineA(或lineB)写入文件并继续扫描。
Do you understand what I said? Could you suggest me a solution?
你明白我说的话吗?你能给我建议一个解决方案吗?
Thanks and sorry for my English :P
感谢和抱歉我的英语 :P
回答by Forgottn
_CrtIsValidHeapPointerUserData means, that you have a heap corruption, which is noticed by debug heap checker. Suspect everybody who can write any information into any deleted dynamic object. And yes, you'll receive heap corruction not immideately on rewrite occurs, but on the next heap check, which will be performed on any next memory allocation/deallocation. However should be simply tracked by a call stack in single threaded applications.
_CrtIsValidHeapPointerUserData 意味着您有一个堆损坏,调试堆检查器会注意到这一点。怀疑任何可以将任何信息写入任何已删除动态对象的人。是的,您不会在重写时立即收到堆损坏,而是在下一次堆检查时收到堆损坏,该检查将在任何下一次内存分配/释放时执行。然而,应该由单线程应用程序中的调用堆栈简单地跟踪。