Debug assertion failed

I keep encountering this "Debug assertions failed!" error when I run my program in debug mode. I tried looking this error up on the visual C++ website but the explanations are too advanced for me and they don't have any resemblance to what my best guess as to the problem is.

I have went through my code and narrowed down the point at which the error occurs. It seems to be happening in the portion of code where I manually delete a whole bunch of heap arrays before the computer moves onto the next part of the program. When I comment out the section that frees up the old heap arrays, the program runs perfectly fine.

Any idea whats going on here? My knowledge in programming is still relatively basic.

Thanks

I'm using Visual C++ 2008.

More information:

The break point triggers at this block of code:

 void operator delete(
    void *pUserData
    )
{
    _CrtMemBlockHeader * pHead;

    RTCCALLBACK(_RTC_Free_hook, (pUserData, 0));

    if (pUserData == NULL)
        return;

    _mlock(_HEAP_LOCK);  /* block other threads */
    __TRY

        /* get a pointer to memory block header */
        pHead = pHdr(pUserData);

         /* verify block type */
        _ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));//<---- break point triggers 

        _free_dbg( pUserData, pHead->nBlockUse );

    __FINALLY
        _munlock(_HEAP_LOCK);  /* release other threads */
    __END_TRY_FINALLY

    return;
}

This code is from the tab: dbgdel.cpp

The section of my code that that I've "narrowed down" that causes this problem is this:

delete [] topQuadanglesPositions;
delete [] fourClamps;
delete [] precaculatedClamp1;
delete [] precaculatedClamp2;
delete [] precaculatedClamp3;
delete [] precaculatedClamp4;
delete [] area;
delete [] hullConfiguration;
delete [] output;
delete [] prunedListClamp1;
delete [] prunedListClamp2;
delete [] prunedListClamp3;
delete [] prunedListClamp4;
delete [] numValidLocations;

If i comment out this section, the program runs fine.


Your code is corrupting the heap. The first snippet is from the C runtime library, the assert is telling you that your program is passing a bad pointer value to the delete operator.

Commenting out the delete statements merely hides the problem. It will come back to haunt you a different way when you keep developing the program. There are some debugging tips in this thread. Learning how to catch these kind of bugs is a rite of passage for any C or C++ programmer. Welcome to the group.


Assertions are statements which only evaluate when you are running in debug mode (Cheap debug checking).

For instance, this would fail assertion in debug, but would not cause an error in release:

ASSERT(1 == 2);

It's likely that some method you are calling expects a certain input and isn't getting it, but it doesn't cause an immediate error (So your code works in non-debug mode.)

Hopefully that's helpful.

If you can post your specific code, someone can probably help you with a more specific response.


Asserts happen when program gets into illegal state. Assert is is written in code by programmer to notify him when something goes bad. You must start debugging from your IDE and press break when you get assert message. Than you should see what is condition in assert, like assert(i > 1024) and make sure that this never becomes true. Maybe you have some comment about meaning of assert, you must find line where it happens and why.

链接地址: http://www.djcxy.com/p/82306.html

上一篇: C ++腐败的堆

下一篇: 调试断言失败