简体   繁体   English

调用std :: vector :: clear时c ++崩溃

[英]c++ crash when calling std::vector::clear

I have a std::vector<Pointer> where pointer is very similar to Boost's intrusive ptr. 我有一个std::vector<Pointer> ,其中的指针与Boost的侵入式ptr非常相似。 There are a couple of differences but the system worked well so for months and I have any doubts that it has any flaws. 虽然有一些差异,但是该系统在几个月内运行良好,因此我怀疑它是否存在缺陷。 The vector contains a list of ~30 interfaces and each element has an implementation to rather complex objects. 该向量包含约30个接口的列表,并且每个元素都有对相当复杂的对象的实现。 The crash happens as follows: 崩溃发生如下:

v.clear() // -> CRASH

Strangely the crash doesn't happen if clear the vector in any other way; 奇怪的是,如果以其他任何方式清除向量,则崩溃不会发生; for example the following code will NOT crash. 例如,以下代码不会崩溃。

while(v.size()) v.pop_back();
or
while(v.size()) v.erase(v.begin());

It also doesn't crash if I compile with the flags "/RTCsu" and "/RTCc". 如果使用标志“ / RTCsu”和“ / RTCc”进行编译,它也不会崩溃。 If I debug the release of all the items happens correctly, it will even exit the clear function successfully, however if eminently after the clear I do "step into" it will go again in the clear function and will crash upon calling the function "iterator end()" 如果我调试所有项目的发布正确发生,它甚至会成功退出清除功能,但是如果在清除之后我确实“进入”,则它会再次进入清除功能,并在调用函数“迭代器”时崩溃结束()”

How is this happening ? 这是怎么回事? What part of the memory should I check for corruption, since the debugger and Application verifier failed to give me any relevant information? 由于调试器和应用程序验证器无法提供任何相关信息,我应检查存储器的哪一部分损坏? Has anyone stumbled upon this issue before? 以前有没有人偶然发现过这个问题?

Is that smart pointer has copy constructor and assignment operator? 该智能指针是否具有复制构造函数和赋值运算符? STL containers store copies of contained items, if there is something wrong with your smart pointer, that might have caused the problem that you described. 如果您的智能指针有问题,则STL容器会存储所包含项目的副本,这可能会导致您描述的问题。

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

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