More delete problems

A couple weeks ago I posted a problem with "delete", http://cplusplus.com/forum/beginner/10266/

The problem was that I was accessing the array out of the bounds before deleting it, giving me a heap corruption.

Now, I have the same code, which works when I run it in VS, but when I build the release and run it, when it gets to the part where it deletes the memory locations, it screws up and asks if I want to debug it. I dont; because it shows some crazy code I've never seen.

All it says is "An unhandled win32 exception occurred in blabla.exe [2804]."?

But if I remove the last "delete [] picTemp;" then there are no problems.

Any ideas?
Last edited on
closed account (S6k9GNh0)
When it debugs, it brings up either ASM or C++. ASM is probably the code your lookin' at.

Try using the debugger inside of VS. It should help you out a bit.
Oh it brings up C++ alright, its just that there must be something wrong with my code, because the code it shows me is some standard windows code that deals with (what I think would be) the delete function.

Go down the call stack. You're at the top, which is the code that throws exceptions. If you go down you'll get to your own code.

And post your code, too. Or is it the same as last time?
Its the same as last time.
code:

- picTemp = new
- main code goes here, edits values in picTemp
- picTemp = delete

I should stress again, that if I just hit the PLAY button in VS2008, it works completely fine, all other functions used in other libraries work bla bla bla everything is peachy (working in release mode).

When I build the release though, thats when it screws up! So I just dont get it.
And I cant move down the stack, because I have to "break" the code, and I can't step through anything without it encountering the error again and asking me to "break" again.
No, don't advance the code (aka step over). Move down the call stack, which stores what functions were called until the current point.
If you're using one of the post 6.0 VSs, you'll find the call stack window in Debug->Windows->Call Stack. I think the default shortcut is alt+7.
Pressing alt f7 does not show me where anything went wrong. Probably because Im running from a built exe? The problem doesnt exist when I debug the code in VS.

It gets stuck in this function: crt0dat.c

Cheers,
Tom
Last edited on
It might be that when you hit the "play," it is running your last successful build. I don't know where the option is...but that is probably what the problem is.
> When I build the release though, thats when it screws up! So I just dont get it.

That is the nature of undefined behavior. It may work in one configuration and crash in another. You need to look for the underlying cause: an out-of-bounds access, a null (or generally bad) pointer dereference, etc.
Alright well it looks like its not a simple enough problem. I will go over my code thoroughly.
Also, about that call stack... I dont get how its supposed to tell me the last function it entered? Can you please explain?

Tom
Topic archived. No new replies allowed.