1
votes

I am getting a heap corruption error when trying to compile my program. The code in question is a pointer

cparticle * particles. 

It is initialized to NULL and then set to

particles = new cparticle[amount]

I am only using delete once in the destructor, and it is causing windows to trigger a breakpoint. I have attempted to use application verifier, and it give me this info:

===========================================================
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.

=======================================

I am unsure what I am doing wrong, so any help will be appreciated.

2
It'll be hard for us to debug this unless we see some more code. - Mysticial
Showing the code would help to figure out what you went wrong. - Vinzenz
Agree with @Mysticial and @Vinzenz. As a first question; did you use delete or delete []? - Ben van Gompel
A couple of clarifications are needed. First - does this happen when you run the program, or (as I think you mistakenly wrote) when you compile it? Second - post your constructor and destructor logic (if not the whole class). Often it helps to add a "cout" to the dtor, so you can tell if there is some unexpected extra delete occuring. - holtavolt
Sorry, it happens when I run the program. The destructor is just delete [] particles, and the constructor is just copying input and particles = NULL; particles = new cparticle[amount]; - user975989

2 Answers

2
votes

The first thing you're doing wrong is you're not using std::vector<particle>.

The second thing is presumably that you're writing to memory past the end of your array of particles.

3
votes

Have you reproduced this in a small standalone program? Are you sure it's not caused by some other memory violation from before that went undetected until now? Are you using the correct delete operator?