Skip to main content
gamedev.net
🔒 Locked

deleting pointers:debug assertion failed

Started by Freaker13 May 2, 2003 at 5:47 AM 7 replies 3.1k views
Original Post
Freaker13
Freaker13
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]
George2
George2
You''re either
1) deleting something which wasn''t new''ed
2) deleting something which was allready delete''ed
"THE INFORMATION CONTAINED IN THIS REPORT IS CLASSIFIED; DO NOT GO TO FOX NEWS TO READ OR OBTAIN A COPY." , the pentagon
janharal
janharal
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..
Freaker13
Freaker13
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;
}
}

Freaker13
Freaker13
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]
janharal
janharal
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
Qw3r7yU10p!
Qw3r7yU10p!
You don''t have to have the checks for NULL.

delete NULL;

is fine. It does nothing.
flangazor
flangazor
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.