![]() |
|
delete operator causing assertion |
Neil Walker
Member #210
April 2000
![]() |
This happens about 1 in 5 times i exit from my game. I'm getting an assertion from the microsoft library (delete operator method in the dbgdel.cpp file) and it's at this line: _ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)); Anyone got a clue what it means! all i'm doing is deleting some memory, as in: delete car; Neil. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Billybob
Member #3,136
January 2003
|
What's the assertion error? It should give you some cryptic assertion error you can good for. Like for me, I would get something like CtrlValidHeapPointer assertion error and Google told me it was about deleting a pointer in the wrong heap.
|
Neil Walker
Member #210
April 2000
![]() |
hello,
*/ the line that my debugger stops me in is in the file dbgdel.cpp (delete operator) on the ASSERT line below: void operator delete( RTCCALLBACK(_RTC_Free_hook, (pUserData, 0)); if (pUserData == NULL) _mlock(_HEAP_LOCK); /* block other threads */ /* get a pointer to memory block header */ /* verify block type */ _free_dbg( pUserData, pHead->nBlockUse ); __FINALLY return; this only happens now and again. when i debug the code where it fails the object i'm deleting is perfectly valid and i can inspect all its data. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
X-G
Member #856
December 2000
![]() |
You're probably trying to delete a dangling or NULL pointer, or something that came from a DLL. -- |
Neil Walker
Member #210
April 2000
![]() |
i don't think so as when i debug the code all data is fine and the code isn't doing anything different i can see when it fails or when it works. however, i've moved the delete statement (deleting some memory created inside a struct) to the destructor of the struct and it seems to behaving itself a bit better. though time will tell Neil. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
X-G
Member #856
December 2000
![]() |
Show code? -- |
Billybob
Member #3,136
January 2003
|
Quote: error is _CrtIsValidHeapPointer(pUserData)
Same error I got.
|
tobing
Member #5,213
November 2004
![]() |
Maybe this will go away if you compile everything to use runtime-DLL (this has helped some people out). |
gillius
Member #119
April 2000
|
A double delete (dangling pointer), a non-initialized pointer, or a pointer from a different heap will cause this assert. A NULL pointer does not cause it, as X-G conjectured, because deleting NULL pointers is safe and well-defined. Gillius |
X-G
Member #856
December 2000
![]() |
What he said. Sorry. I should know that. -- |
Billybob
Member #3,136
January 2003
|
Quote: because deleting NULL pointers is safe and well-defined. Actually, deleting a NULL pointer under MSVC 6 will cause an assert. I've run into it, kind of annoying. Not that it's bad, or will crash in Release mode, but it certainly asserts.
|
gillius
Member #119
April 2000
|
Uh are you sure about that WH? I've long since deleted my copy of VC6, so I can't test it anymore, but I certainly don't remember its delete operator asserting on "delete 0;" and I used MSVC6 for a few years to do all of my C++ programming. Gillius |
tobing
Member #5,213
November 2004
![]() |
I'm also wondering about this 'delete 0' causes an assert. Never seen that, I'm using MSVC 6.0 7.0 7.1 for years now. |
Tobias Dammers
Member #2,604
August 2002
![]() |
If delete 0; raises an assert in MSVC, then it's even worse than I always thought. ASSERT(NULL) should of course assert, but delete NULL shouldn't. --- |
Chris Katko
Member #1,881
January 2002
![]() |
Quote: I'm also wondering about this 'delete 0' causes an assert. I'm confused. You can't write delete 0, or delete NULL. NULL (and '0') isn't a pointer. So I'm just going to assume you mean variable containing a null pointer. If this: int *temp = new int; delete temp; delete temp; is what you're talking about, yes, it crashes (or gives an unhandled exception in debug mode) when using MSVC6. Quote: then it's even worse than I always thought. How good do you expect a compiler to be that's made before the specification is standardized? -----sig: |
gillius
Member #119
April 2000
|
Hmm 0 is implicitly convertable to any type of pointer, as guaranteed by the standard, so I thought delete 0; would work. In fact, GCC won't compile that, so I wonder. Casting it to int* or making "int* i=0; delete i;" does work. Gillius |
Chris Katko
Member #1,881
January 2002
![]() |
Quote: Casting it to int* or making "int* i=0; delete i;" does work.
Yes, I guess I just misinterpreted what you were saying. -----sig: |
gillius
Member #119
April 2000
|
No, you didn't misinterpret me. I literally meant "delete 0;" when I said that, but at the time I honestly thought it would work. On GCC at least, it doesn't. Gillius |
Billybob
Member #3,136
January 2003
|
Man, I have bad memory
|
|