利用MFC处理图像二值化一直出错,而且是运行完成后出错

代码如下希望大大们解答!!!好纠结
BOOL CCarDoc::getotsu(unsigned char * lpDIBBits, LONG lWidth, LONG lHeight)
{
unsigned char * lpNewDIBBits;
unsigned char* lpDst;
LONG lLineBytes;
// 计算图像每行的字节数
lLineBytes = (((lWidth * 8) + 31) / 32 * 4);
double N[256] = { 0 };
double N2[256] = { 0 };
int Nt;
int t[256];
double max = 0;
double uT = 0, uT2 = 0;
double w = 0, w2 = 0;
double u = 0, u2 = 0;
double uj, uj2;
double k, k2 = 0;
int the = 0, the2 = 0;
int s = 0;
lpNewDIBBits = new unsigned char[lLineBytes * lHeight];

// 判断是否内存分配失败
if (lpNewDIBBits == NULL)
{
    // 分配内存失败
    return FALSE;
}

// 初始化图像为原始图像
memcpy(lpNewDIBBits, lpDIBBits, lLineBytes * lHeight);
for (int i = 0; i <lHeight; i++)
{

    for (int j = 0; j < lWidth; j++)
    {
        lpDst = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j;
        N[*lpDst]++;
    }

}
Nt =lHeight*lLineBytes;
for (int i = 0; i < 256; i++)
{
    N[i] = N[i] / Nt;

}
for (int i = 0; i < 256; i++)
{
    uT += i*N[i];
}

for (int i = 0; i < 256; i++)
{
    w += N[i];
    u += i*N[i];
    uj = u / w;
    k = uT*w - u;
    k = k*k / (w*(1 - w));

    if (k>max)
    {
        max = k;

        the = i;
    }

}
for (int i = 0; i <lHeight; i++)
{

    for (int j = 0; j < lWidth; j++)
    {
        lpDst = (unsigned char*)lpNewDIBBits + lLineBytes * (lHeight - 1 - i) + j;
        if (*lpDst<the)
        {
            *lpDst = 0;
        }
        else
        {
            *lpDst = 255;
        }
    }

}
memcpy(lpDIBBits, lpNewDIBBits, lLineBytes * lHeight);



delete lpNewDIBBits;

// 返回
return TRUE;

}

和你delete有关

http://download.csdn.net/download/wyj1046/2922444

图片说明
这是错误的原因,但是不知道断点在哪里

点中断看下
代码中有断点

点一下中断看看断到哪里了。

点击中断出现了这个。。哭死了图片说明

更改PDB和文件搜索路径咯