I am using the following code.
Code:
void CPathFind::AllocatePathFindInfoMem(void){
    if (g_pCarPathInfos){
        delete [] g_pCarPathInfos;
        g_pCarPathInfos = NULL;
    }
    if (g_pPedPathInfos){
        delete [] g_pPedPathInfos;
        g_pPedPathInfos = NULL;
    }
    if (g_pTempDetachedNodes){
        delete [] g_pTempDetachedNodes;
        g_pTempDetachedNodes = NULL;
    }


    g_pCarPathInfos = new CPathInfoForObject[12288];
//    memset(g_pCarPathInfos, 0, sizeof(CPathInfoForObject) * 12288);
    g_pPedPathInfos = new CPathInfoForObject[14568];
    memset(g_pCarPathInfos, 0, sizeof(CPathInfoForObject) * 14568);
    g_pTempDetachedNodes = new CTempDetachedNode[4600];
    memset(g_pTempDetachedNodes, 0, sizeof(CTempDetachedNode) * 4600);
    g_nPedGroupNodes = 0;
    g_nCarGroupNodes = 0;
}


void CPathFind::PreparePathData(void){
    //CDebug::DebugAddText("Custom Code: PreparePathData");
    if ( g_pCarPathInfos && g_pPedPathInfos && g_pTempDetachedNodes){
        CTempNode* pTempNodes = new CTempNode[5000];
        m_nAttachedPoints = 0;
        m_nAttachedNodes = 0;
        PreparePathDataForType(PATHDATAFOR_CAR, pTempNodes, NULL, 1.0f, g_pCarPathInfos, g_nCarGroupNodes);
        m_nCarAttachedNodes = m_nAttachedNodes;
        PreparePathDataForType(PATHDATAFOR_PED, pTempNodes, NULL, 1.0f, g_pPedPathInfos, g_nPedGroupNodes);
        m_nPedAttachedNodes = m_nAttachedNodes - m_nCarAttachedNodes;
        if (pTempNodes)
            delete [] pTempNodes;
        CountFloodFillGroups(PATHDATAFOR_CAR);
        CountFloodFillGroups(PATHDATAFOR_PED);
        delete [] g_pCarPathInfos;
        g_pCarPathInfos = NULL;
        delete [] g_pPedPathInfos;
        g_pPedPathInfos = NULL;
        if (g_pTempDetachedNodes)
            delete [] g_pTempDetachedNodes;
        g_pTempDetachedNodes = NULL;
    }
The 2 functions belong to a class named CPathFind. The variable whose prefixes begin with g_ are the static elements of the class.

At first the AllocatePathFindMemInfo is called and then at last the PreparePathData is called. And the error is encountered at this line :
delete [] g_pCarPathInfos;

MSVC then gives me this error
Code:
Windows has triggered a breakpoint in NewPathFind.exe.


This may be due to a corruption of the heap, which indicates a bug in NewPathFind.exe or any of the DLLs it has loaded.


This may also be due to the user pressing F12 while NewPathFind.exe has focus.


The output window may have more diagnostic information.
Help!