Advertisement

More code help needed

Started by March 10, 2001 09:48 PM
1 comment, last by Radhil 23 years, 11 months ago
I''m really getting tired of this. Is there any circumstance where a delete call will fail, even if it''s given the exact same pointer that came from a new? I have a class object that handles my input for a game. It''s based off the Singleton in that book Design Patterns, so I have two static functions and one static member. The first static function, when it''s first called, creates the module data off of a new, sets up DirectInput and all that, and puts the pointer in the static member. That static member is NEVER ALTERED. The second static function shuts down all the DirectInput stuff, then calls delete on the static pointer. On the delete call, program goes boom. Specifically, it gives me a Debug Library box, with the statement, DAMAGE: after Normal block (#20) at (hex code). I''ve stored the value of the pointer in a separate global, and compared the values IMMEDIATELY AFTER the new call and IMMEDIATELY BEFORE the delete call. They match perfectly. The pointer was never changed, or damaged, or overwritten. The delete call fails. WTF? Radhil Trebors Persona Under Construction
Radhil TreborsPersona Under Construction
If you created the object with new [] you need to use delete []... the only way delete will fail is if you forget what i just said and the pointer is NULL...

at least as far as i know... so it is always good to just do

if (object)
{
delete object;
}

if you did a new []

Obj object = new Obj[10];

you NEED to use delete[] object; instead...

hope this helps yo seems pretty frustated there....

-= spacemadness
Advertisement
Nope, the original new call was not an array. And yes, I''m checking for a NULL condition.

For all intents and purposes, the delete call should be good. Even in a watch window, the pointer seems fine, and it matches it''s original value.

Maybe I should buy a clue from the last problem I posted here, and start looking for a leak elsewhere in the program.

Radhil Trebors
Persona Under Construction
Radhil TreborsPersona Under Construction

This topic is closed to new replies.

Advertisement