Assertion failed! at delete[]

Started by
4 comments, last by WuTz 14 years ago
Hello! I've got another problem. Sometimes, when I do this:

void PckFileChunk::DeleteData()
{
    if(Data)
    {
       delete[] Data;
       Data=NULL;
    }
}


I get this: Image and video hosting by TinyPic And I already checked if Data (Which is of the type Byte*) is invalid, and it is.(Or maybe not?) What causes this "assertion failed"?
Advertisement
(1) CrtIsValidHeapPointer checks if a pointer is referring to space in the local heap.
(2) It is redundant and unnecessary to check "if(Data)" before invoking delete[]. delete[] on a null pointer is a safe no-op.
So, what can I do?

PS: 2. is cool, I didn't knew that! :)
Debug your code.

The pointer you are trying to delete isn't in the local heap. That means it has a bad value. This could be because of any number of reasons; you assigned it a value that you'd already deleted, you overwrite memory elsewhere, stomping on the object that contains the Data member such that it refers to an invalid address, et cetera.
Stupid question, but did you accidentally make Data point to a stack object?
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
I've fixed the problem now. Over some wired ways, I found out that I passed the data from a ID3D10Blob interface directly. And this interface deletes the memory when it gets released.

Everything is fine now :)

This topic is closed to new replies.

Advertisement