Jump to content
  • Advertisement
Sign in to follow this  
Mastadex

Memory Error - HELP

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My game is crashing at the destructor call of one of my objects. Basically here is what I have briefly: void func() { Obj *ObjPtr[65]; for (int x = 0; x < 65; x++) { ObjPtr[x] = new Obj(params, params); } // most of the function code goes here for (int x = 0; x < 65; x++) { delete ObjPtr[x]; <-----------CRASH } } Honestly, I have tried everything i know to fic this. Even switching it to: delete [] ObjPtr; That dodnt work either. Im using VisualStudio .NET 2003 and the specific error i get is: Debug Error DAMAGE: after normal block 0x########. Any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
This warning means that your trying to deletememory that doesn't belong to you. Usually its been deleted allready, or it was never allocated and your pointing to memory that you didnt' allocate.

What is the value of x at this time??
try setting the values to NULL after you delete them, you'll find this practice saves you a good deal of time.

Cheers
Chris

Share this post


Link to post
Share on other sites
Stompy's change won't change anything.

I suggest you look into what specific address it's complaining about, and set a data breakpoint in your program after allocation, and see who changes it.

Also, you can cut out parts of the program, until it works, and then add parts back until it breaks; then you know where to look for the problem.

Share this post


Link to post
Share on other sites
I tried it both ways, it still complains. Any other suggestions are appreciated. Although the program does work fine without including the delete statement. But i know thats a huge memory leak...

Share this post


Link to post
Share on other sites
The problem is not the delete, that message probably means that you overwrote the 'fences' around your block of memory. The fences are what the debugger uses to tell if you've written past the ends of your array/memory. If it doesn't find the values it puts at the ends of the block when you delete the memory, it gives you that message because it knows you wrote something outside of the allocated memory.

Check for array indices out of bounds, that sort of thing.

Share this post


Link to post
Share on other sites
I would virtually guarantee that you have an array bounds overflow problem. For probably every other person on GDNET who's had that problem, that was the cause. It's also extremely likely that you aren't using asserts, which is also common in cases like this.

The answer is to put assert()'s in at the place where you access an array, particularly whenever you write to an array, assert that the index is ">= 0" and "< arrayMax". Most likely, this WILL show you what the error is. Do this now.

Share this post


Link to post
Share on other sites
Another way to check if you'r deleting stuff that has been deleted before would be to set ObjPtr[x] = 0 after you delete it. This won't help if you've got dangling pointers somewhere else, but it will let you see if your deleting the same thing twice from ObjPtr...

hth
moe.ron

Share this post


Link to post
Share on other sites
Quote:
Original post by moeron
Another way to check if you'r deleting stuff that has been deleted before would be to set ObjPtr[x] = 0 after you delete it. This won't help if you've got dangling pointers somewhere else, but it will let you see if your deleting the same thing twice from ObjPtr...

hth
moe.ron


ahhhm

What is the value of x at this time??
try setting the values to NULL after you delete them, you'll find this practice saves you a good deal of time.

This has been covered:)

CHeers
Chris

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!