尝试编译程序时出现堆损坏错误。有问题的代码是一个指针
cparticle * particles.
将其初始化为NULL,然后设置为
particles = new cparticle[amount]
我只在析构函数中使用delete一次,它导致windows触发断点。我试图使用应用程序验证程序,它给了我这个信息:
===========================================================
VERIFIER STOP 0000000000000013: pid 0x17C0: first chance access violation for current stack trace
000000001D54A0A4 : Invalid address being accessed
0000000055741DC6 : Code performing invalid access
000000000025E9D0 : Exception record. Use .exr to display it.
000000000025E4E0 : Context record. Use .cxr to display it.
===========================================================
This verifier stop is continuable.
After debugging it use `go' to continue.
===========================================================
=======================================
VERIFIER STOP 00000013: pid 0x17C0: First chance access violation for current stack trace.
1D54A0A4 : Invalid address causing the exception.
55741DC6 : Code address executing the invalid access.
001DF30C : Exception record.
001DF35C : Context record.
=======================================
This verifier stop is continuable.
After debugging it use `go' to continue.
=======================================
我不确定我做错了什么,所以任何帮助都会受到赞赏。
答案 0 :(得分:3)
您是否在一个小型独立程序中复制了这个?你确定它不是由于之前的一些其他内存违规造成的,直到现在才被发现吗?您使用的是正确的删除操作符吗?
答案 1 :(得分:2)
你做错的第一件事就是你没有使用std::vector<particle>
。
第二件事可能是你在你的粒子数组末尾写入记忆。