我有以下 C++ 方法:
void MyClass::FindBottom ( CIppImage& bwImage, FieldRec* obField, int& bottomBorder_top, int& bottomBorder_bottom, int& topBorder_top, int& topBorder_bottom, bool& algoFoundBorder ){
int scanYStart = topBorder_top + obField->getH() - VERTICAL_SCAN_AMOUNT;
int scanYEnd = topBorder_top + obField->getH() + ( VERTICAL_SCAN_AMOUNT * 1.5 );
int scanAmount = scanYEnd - scanYStart;
int xScanEnd = obField->getOX() + obField->getW();
int* histogram = new int[ scanAmount ];
memset ( histogram, 0, (scanAmount) * sizeof(int) );
Ipp8u* bwDataPtr = bwImage.DataPtr();
int bwLineWidth = ( bwImage.Width() + 7 ) / 8;
int n = 0;
for( int y = scanYStart; y <= scanYEnd; y++ ){
for( int x = obField->getOX(); x < xScanEnd; x++ ){
if( ( GETBYTE( bwDataPtr, x, y, bwLineWidth ) ) != 0 && ( GETPIXEL(bwDataPtr, x, y, bwLineWidth ) ) != 0 ){
histogram [ n ]++;
}
}
n++;
}
int numFillPixelsThreshold = (int)(HORIZ_FILL_THRESHOLD * obField->getW());
vector<int> goodRows;
for( int j = 0; j < VERTICAL_SCAN_AMOUNT+VERTICAL_SCAN_AMOUNT+1; j ++ ){
if( histogram[ j ] >= numFillPixelsThreshold ) {
goodRows.push_back( scanYStart + j );
}
}
if( goodRows.size() > 0 ){
bottomBorder_top = goodRows[0];
bottomBorder_bottom = goodRows[goodRows.size()-1];
algoFoundBorder = true;
}else{
bottomBorder_top = obField->getOY() + obField->getH() - 4;
bottomBorder_bottom = obField->getOY() + obField->getH() + 4;
algoFoundBorder = false;
}
delete[] histogram;
histogram = 0;
}
有 1 个特定实例delete[]
调用使程序崩溃,Visual Studio 返回错误消息:
检测到堆损坏:在 0x01214980 CRT 的正常块 (#44325) 后检测到应用程序在堆缓冲区结束后写入内存。
有任何想法吗?