Failed to debug

I continue to encounter this error "Debug assertions failed!"when running my program in debug mode. I tried to find this error on the C ++ visual website, but the explanations are too advanced for me, and they bear no resemblance to my best guess about the problem.

I looked at my code and narrowed down the point at which the error occurs. This seems to be happening in that part of the code where I manually delete the whole bunch of heap arrays before the computer moves to the next part of the program. When I comment on a section that frees old heap arrays, the program works fine.

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

thank

I am using Visual C ++ 2008.

Additional Information:

The breakpoint is triggered in 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 in the tab: dbgdel.cpp

The section of my code that I “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 on this section, the program works fine.

+3
source share
3 answers

Your code damages a bunch. The first fragment from the C runtime library, the statement tells you that your program passes the value of a bad pointer to the delete operator.

. , -, . . , , - C ++. .

+7

- , ( ).

, , :

ASSERT(1 == 2);

, - , , , ( .)

, .

, -, , .

+2

, . , , - . IDE , assert. , assert, assert(i > 1024), , . , - assert, , .

+1

Source: https://habr.com/ru/post/1765698/


All Articles