损坏的堆栈
corrupted stack
这是我的函数,它显示
变量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(void*hDib,int nQuality,ATL::CStringT>>csJpeg,ATL::CStringT>>*pcsMsg)行551+0x28字节C++
错误消息:运行时检查失败#2-变量"cinfo"周围的堆栈已损坏。pcsMsg定义:CString*pcsMsg
jpeg_destroy_compress(&cinfo);
释放一个自动变量的内存,当cinfo
超出作用域时会第二次释放该内存。
函数jpeg_destroy_compress()应解除分配并释放与压缩对象相关的所有内存。
相关文章:
- 将大双精度转换为无符号 int 期间堆栈损坏
- 程序终止时堆栈损坏?
- 为什么我的visual c++在堆栈损坏的情况下没有触发堆栈损坏错误
- 调试堆栈损坏问题
- 如何在退出时修复OpenGL堆栈损坏
- OpenCV C++:声明一个新变量会导致堆栈损坏
- 使用 sscanf 堆栈损坏
- C#到C代码P/调用多个std:字符串声明导致堆栈损坏
- 填充数组会导致数组周围的堆栈损坏
- 试图计算fibonacci(n)的变量“f”周围的堆栈损坏
- C++-如何在程序退出时找到堆/堆栈损坏的源
- 链表实现的堆栈损坏
- 可视化C++映射迭代和堆栈损坏
- 在 c++ 中 int 数组周围堆栈损坏错误
- 测试《毁灭战士3》堆栈实现时堆栈损坏
- 如何知道析构函数中的堆栈损坏来自何处
- 在c++中添加int数组时,试图找出堆栈损坏的问题
- 用错误的“”调用构造函数;这个“;指针.这是堆栈损坏吗
- GetCPUDescriptorHandleForHeapStart堆栈损坏
- memcpy之后堆栈损坏