스택

2012-08-24 2 views
0

손상이 제 기능이며이 변수 CINFO 주위스택

스택이 손상되었습니다 말한다.

이 코드는 마지막 줄의 551 행에 문제가 있다고합니다.

struct jpeg_compress_struct cinfo; 
struct jpeg_error_mgr  jerr; 

FILE*  pOutFile;  //Target file 
int  nSampsPerRow; //Physical row width in image buffer 
JSAMPARRAY jsmpArray; //Pixel RGB buffer for JPEG file 

cinfo.err = jpeg_std_error(&jerr); //Use default error handling (ugly!) 

jpeg_create_compress(&cinfo); 

if ((pOutFile = fopen(csJpeg, "wb")) == NULL) 
{ 
    *pcsMsg = "Cannot open "; 
    *pcsMsg += csJpeg; 
    jpeg_destroy_compress(&cinfo); 
    return FALSE; 
} 

jpeg_stdio_dest(&cinfo, pOutFile); 

LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)hDib; 

cinfo.image_width  = lpbi->biWidth; //Image width and height, in pixels 
cinfo.image_height  = lpbi->biHeight; 
cinfo.input_components = 3;    //Color components per pixel 
             //(RGB_PIXELSIZE - see jmorecfg.h) 
cinfo.in_color_space = JCS_RGB;  //Colorspace of input image 

jpeg_set_defaults(&cinfo); 

jpeg_set_quality(&cinfo, 
       nQuality, //Quality: 0-100 scale 
       TRUE); //Limit to baseline-JPEG values 

jpeg_start_compress(&cinfo, TRUE); 

//JSAMPLEs per row in output buffer 
nSampsPerRow = cinfo.image_width * cinfo.input_components; 

//Allocate array of pixel RGB values 
jsmpArray = (*cinfo.mem->alloc_sarray) 
      ((j_common_ptr) &cinfo, 
      JPOOL_IMAGE, 
      nSampsPerRow, 
      cinfo.image_height); 

if (DibToSamps(hDib, 
       nSampsPerRow, 
       cinfo, 
       jsmpArray, 
       pcsMsg)) 
{ 
    //Write the array of scan lines to the JPEG file 
    (void)jpeg_write_scanlines(&cinfo, 
           jsmpArray, 
           cinfo.image_height); 
} 

jpeg_finish_compress(&cinfo); //Always finish 

fclose(pOutFile); 

jpeg_destroy_compress(&cinfo); //Free resources 

if (*pcsMsg != "") 
    return FALSE; 

else 
    return TRUE; 
} 

스택 추적!> WindowBitmap.exe CBitmapFile :: JpegFromDib (무효 * hDib, INT의 nQuality, ATL :: CStringT>> csJpeg, ATL :: CStringT>> * pcsMsg) 라인 551 + 0x28을 바이트 C++

오류 메시지 : Runtime Check Failure # 2 - 'cinfo'변수 주위의 스택이 손상되었습니다. pcsMsg 정의 : CString을 * pcsMsg

+0

스택 추적 및 오류 메시지를 게시 할 수 있습니까? – noisecapella

+0

a) 스택이 손상되었다고 말하는 것은 무엇입니까? b) 매개 변수는 무엇입니까? 그 pcsMsg의 사용이 이상하게 보입니다 –

+0

당신은'pcsMsg'의 정의와 함수 프로토 타입을 제공 할 수 있습니까? 귀하의 설정을 사용하여 pcsMsg가 잘못 보입니다 –

답변

0
jpeg_destroy_compress(&cinfo); 

cinfo은이 범위를 벗어나면 제 시간을 해제하는 자동 변수의 메모리를 해제.

jpeg_destroy_compress() 함수는 압축 객체와 관련된 모든 메모리를 할당 해제하고 해제해야합니다.