new, delete시 에러가 발생합니다..
글쓴이: sada0220 / 작성시간: 월, 2010/02/22 - 8:44오후
int out_width = 320;
int out_height = 240;
int nbytes = avpicture_get_size(PIX_FMT_BGR24, out_width, out_height);
unsigned char* outbuffer = new unsigned char[nbytes];
static struct SwsContext *img_convert_ctx;
img_convert_ctx = sws_getContext(pCodecCtx->width,
pCodecCtx->height, pCodecCtx->pix_fmt,
pCodecCtx->width, pCodecCtx->height,
PIX_FMT_BGR24, SWS_BICUBIC, NULL, NULL, NULL);
sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
int j;
for(i=0;i<240;i++)
{
for(j=0;j<320;j=j+1)
{
int numOfArray = ((i*320)+j)*3;
int numOfOutArray = (((240-i-1)*320)+j)*3;
outbuffer[numOfOutArray] = pFrameRGB->data[0][numOfArray+0];
outbuffer[numOfOutArray-1] = pFrameRGB->data[0][numOfArray+2];
outbuffer[numOfOutArray-2] = pFrameRGB->data[0][numOfArray+1];
}
}
delete [] outbuffer;
delete할때 에러가 발생하는데, 코드가 문제가 있는건가요??
맞게 작성 되었다고 생각되는데....
아시는 분 답변 부탁드립니다!!
Forums:


index bound error입니다.
i == 239 && j == 0 인 경우 numOfOutArray는 0이 됩니다.
그럼 outbuffer[-1] 과 같은 곳에 접근하게 되고 heap 이 깨지면서 delete[] 시에 문제가 발생합니다.
const int out_width =
const int out_width = 320; const int out_height = 240; ... int numOfArray = 0; int numOfOutArray = 0; int startNumOfOutArray = (out_height - 1) * out_width*3; for(int i = 0; i < out_height; ++i) { numOfOutArray = startNumOfOutArray; for(int j = 0; j < out_width; ++j) { outbuffer[numOfOutArray + 2] = pFrameRGB->data[0][numOfArray]; outbuffer[numOfOutArray + 1] = pFrameRGB->data[0][numOfArray + 2]; outbuffer[numOfOutArray] = pFrameRGB->data[0][numOfArray + 1]; numOfArray += 3; numOfOutArray += 3; } startNumOfOutArray -= out_width * 3; }멀티어레이가 더 나을 듯.
delete시에 에러나는 상당수는...
범위 벗어나서 데이터를 쓸때 문제더군요...
댓글 달기