std::set::erase 上的访问冲突读取位置
我最近在我的应用程序中发现了以下崩溃:
m_players[0].erase(plr); -- CRASHES HERE
m_players[1].erase(plr);
m_players
声明为:
set<PlayerPointer> m_players[2];
Visual Studio 显示它是“0xC0000005:访问冲突写入位置 0x0000000000000024”。
编译器:Visual Studio 2008。
反汇编:000000014007AA3B mov rcx,qword ptr [this](崩溃)
所以我假设我们会因为坏的“this”而死,因为它是该函数中第一次访问 this 。但自从我看了当地人/汽车后,这似乎并不是一个糟糕的指针。
得到提示会很高兴。
I have recently caught the following crash in my application:
m_players[0].erase(plr); -- CRASHES HERE
m_players[1].erase(plr);
m_players
is declared as:
set<PlayerPointer> m_players[2];
Visual Studio shows that it is "0xC0000005: Access violation writing location 0x0000000000000024."
Compiler: Visual Studio 2008.
Diassembly: 000000014007AA3B mov rcx,qword ptr [this] (crashed on)
So I'm assuming we're dying because of bad "this", since its a first access to this in that function. But since I watched locals/autos, this doesn't seem to be a bad pointer.
Would be nice to get a hint.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有些东西指向 0。当您使用 Visual Studio 时,请在调试模式下编译您的应用程序。键入 Ctrl+Alt+E 并在引发异常时激活异常。这将帮助您在运行异常处理程序之前检测出出错的地方。然后您可以发布调用堆栈,但我认为您将自己轻松地看到并解决问题。我可以想象 plr 的任何类型的析构函数中都会有一些不好的事情。
Something is pointing to 0. As you are using Visual Studio compile your application in Debug mode. Type Ctrl+Alt+E and activate the exceptions when they are thrown. This will help you to detect places where things go wrong before an exception handler is run. You can then post the callstack, but I think you will then see&solve the problem easily yourself. I can imagine something bad in the destructor of whatever type is plr.
使用 Visual Studio 时,最好确保运行时相同。你验证过吗? (例如多线程调试 DLL (/MDd))
When working with Visual Studio, it is always good to ensure the runtimes are the same. Have you verified that? (e.g. Multi-threaded Debug DLL (/MDd))
我认为这与 plr 的关系大于 m_players 已被删除或不可用的关系。你能展示一下如何获得 plr 吗?它是局部变量还是作为参数传递?您可能想创建一个局部变量,然后在擦除函数中使用它,看看它是否崩溃。这样您就可以查明到底是什么导致了崩溃。
I think this has more to do with plr than m_players being already deleted or not available. Can you show how you get plr, is it a local variable or is it being passed as an argument? You might want to create a local variable and then use it in erase function and see if it crashes. This way you can pin point what exactly is causing the crash.
数组是否有可能是全局的,并且有问题的代码在数组初始化之前执行(如果它位于全局对象的构造函数等内部,则可能会发生)?
any chance the array is global and the problematic code is executed before the array is initialized (can happen if its inside a constructor of a global object etc) ?