Advertisement

Odd Debug Assertion Error with Delete

Started by August 11, 2000 05:55 PM
5 comments, last by SeanHowe 24 years, 4 months ago
Ok, I''m getting a debug assertion error when I use the delete operator on a dynamically allocated array of a class. Normally I''d be able to handle this. However, the problem is, it only happens every about 1 out of 4 times I run the program. I''ve looked through my code, and can''t find anything wrong. I''m not looking for help with my code, just ideas as to what might be causing this weird behavior. Thanx.
what is the class? What is the array for?
Advertisement
Since it doesn''t always happen, try to find events in the program unique to the times that it does give the error.

E.g. if its a game, and you get killed by a particular enemy and you get the assertion error, but when you don''t get killed by that enemy there''s no assertion error, then you would want to look at the related code.

Basically be a detective. Look for clues that lead to the assertion error.

Unfortunately these types of things are the hardest to find, especially on programs that are big and complex.

Good luck.

I guess this is where most people put a famous quote...
"Everything is funnier with monkey''s" - Unknown
--------------------------I guess this is where most people put a famous quote..."Everything is funnier with monkey''s" - Unknown
Perhaps you are doing a double delete? If two areas of code are sharing the same memory, and one is deleted, and then another area of code decides to free it up, you may get an assertion error for a double deallocation....

CodeMonkey
CODE Monkey
It''s happenning in my exiting code, so, no special conditions to be happening there. I''ll take a look for what you suggested, codemonkey.
Yep, I was deleting it twice, in the most elaborate of elaborate ways.
What I had, was, in my main message loop, it checked to see if there was a message in the message que, and if it was WM_QUIT, it broke from the loop. My shutdown function posted a WM_QUIT message after releasing all the game objects. However, I was only checking once to see if there was a message. Every once in a while, there''d be multiple messages in the que before I posted WM_QUIT. So, it wouldn''t retrieve it till a couple more times through the loop. This caused it to call the release function again, which tried to delete stuff I had already deleted. So, I fixed it my changing my if (PeekMessage.. to while (PeekMessage..

Thanx for everyone''s help, especially codemonkey, I never would''ve found this without you.
Advertisement
Glad to see my suggestion helped out. It was on my brain because I''ve been fixing memory leaks and other issues for the last two weeks at work, and I''ve got all the fixes still fresh in my brain

Happy coding!


CodeMonkey
CODE Monkey

This topic is closed to new replies.

Advertisement