Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Freaker13

deleting pointers:debug assertion failed

This topic is 5623 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

Hi all, When i delete pointers i get the following run-time error: debug assertion failed! file dbgdel.cpp Expression:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse) this is my code:
      
sData()
{
	totalTime = time = aantal = 0;
	name = NULL;
	timer = NULL;
}
~sData()
{
	delete name;
	name = NULL;
	delete timer;
	timer = NULL;
}
}sData;

static sData  *data = NULL;

void cProfiler::free()
{
     delete []data;
     data = NULL;
     delete path;
     path = NULL;
}
    
Can someone explain me what i'm doing wrong? thx in advance [edited by - Freaker13 on May 2, 2003 6:48:57 AM]

Share this post


Link to post
Share on other sites
Advertisement
You''re either
1) deleting something which wasn''t new''ed
2) deleting something which was allready delete''ed

Share this post


Link to post
Share on other sites
Seems like you''re deleting an uninitialized (or already deleted) pointer.
''path'' isn''t initialized in your code-snippet. Otherwise I can''t see anything wrong..
(and it isn''t strictly necessary to set pointers to NULL in a deconstructor, as the variables can''t be referenced afterwards anyway (unless they''re static))

Run the debugger and see exactly what variable is causing the error - it''s probably easier to find the error then..

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
both pointers give the same error(data and path). they are not deleted and are initialised.

Share this post


Link to post
Share on other sites
i''ve checked them on NULL pointers now. But i still get the same error.

void cProfiler::free()
{
if(data != NULL)
{
delete []data;
data = NULL;
}
if(path!= NULL)
{
delete path;
path = NULL;
}
}

Share this post


Link to post
Share on other sites
I've found it:
with strings i didn't use the new keyword like
char* path;
path = "string";

So don't i have to delete those string pointers?



[edited by - Freaker13 on May 2, 2003 7:51:55 AM]

Share this post


Link to post
Share on other sites
No, you don''t.

Unless you use the new keyword, variables are located on the stack and it is not necessary (or correct) to delete them.

As a rule: one new -> one delete

Share this post


Link to post
Share on other sites
I have had this and I memorized that it is virtually ALWAYS when you have a crap ass copy constructor and pass an object by value. Pass by const reference.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!