简体   繁体   English

C ++-调试断言在程序退出时失败

[英]C++ - Debug Assertion Failed on program exit

When calling 'exit', or letting my program end itself, it causes a debug assertion: 当调用“退出”或让我的程序自行结束时,它会导致调试断言:

调试断言失败 .

Pressing 'retry' doesn't help me find the source of the problem. 按“重试”并不能帮助我找到问题的根源。 I know that it's most likely caused by memory being freed twice somewhere, the problem is that I have no clue where. 我知道这很可能是由于某处的内存被释放两次而导致的,问题是我不知道在哪里。

The whole program consists of several hundred thousand lines which makes it fairly difficult to take a guess on what exactly is causing the error. 整个程序由数十万行组成,这使得很难确切猜测是什么导致了错误。 Is there a way to accurately tell where the source of the problem is located without having to comb line for line through the code? 有没有一种方法可以准确地指出问题的根源,而不必在代码中逐行梳理?

The callstack doesn't really help either: 调用栈实际上也没有帮助:

调用堆栈 .

this kind of errors usally appear if you delete already deleted objects. 如果删除已删除的对象,通常会出现这种错误。

this happens if one object is given to multiple other objects that are supposed to take ownership of that first object and both try to delete it in their destructor. 如果将一个对象提供给应该拥有第一个对象所有权的多个其他对象,并且两者都尝试在其析构函数中删除它,则会发生这种情况。

As the messagebox already suggests, you're probably corrupting your heap in some way. 正如消息框已经暗示的那样,您可能以某种方式破坏了堆。 Either you free/delete some memory block that you should not or you're trying to write to some memory block that has already been freed/deleted. 您释放/删除了您不应该使用的某个内存块,或者您尝试写入已经释放/删除的某个内存块。

The callstack suggests that this is probably happening when stepping over the last line of your main function. 调用堆栈表明,这可能在单步执行main函数的最后一行时发生。 If that is the case, then the problem is probably in the cleanup routines of some user defined types of which you create instances inside the main function. 如果真是这样,那么问题可能出在某些用户定义类型的清除例程中,您可以在main函数中创建其实例。 Try setting breakpoints inside the destructors of your own classes and investigate. 尝试在自己的类的析构函数中设置断点并进行调查。

It is possible that you are corrupting the heap during the program operation, but it is not being detected until the end of the program, in which case the stack trace would only point to the memory checking routine 您可能在程序操作期间破坏了堆,但是直到程序结束才检测到堆,在这种情况下,堆栈跟踪只会指向内存检查例程

There may be a function you can call during operation that checks if the heap is valid, which may bring the fail closer to the point of corruption 您可能在操作期间可以调用一个函数来检查堆是否有效,这可能使失败更接近破坏点

HeapValidate is an example of such a routine, but it would depend on what platform you are using HeapValidate是此类例程的一个示例,但这取决于您使用的平台

This error can also happen when you use delete[] instead of delete . 当您使用delete[]而不是delete时,也会发生此错误。 However, as mentioned, this is only one of many causes. 但是,如上所述,这只是许多原因之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM