求解 将一个无效参数传递给了将无效参数视为严重错误的函数 是什么错误啊

sunny晓美圆 2015-02-22 10:00:10

使用libpng时出现的错误

执行到此处时调试报错:ca4.exe 已触发了一个断点。点继续提示:0x0FD72793 (appcrt140d.dll) (ca4.exe 中)处有未经处理的异常: 将一个无效参数传递给了将无效参数视为严重错误的函数。
调试输出如下:
Debug Assertion Failed!

Program: ...\test\Documents\Visual Studio 2015\Projects\ca4\Debug\ca4.exe
File: f:\dd\vctools\crt\core_crt\src\appcrt\lowio\read.cpp
Line: 498

Expression: _osfile(fh) & FOPEN

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
Second Chance Assertion Failed: File f:\dd\vctools\crt\core_crt\src\appcrt\internal\winapi_nonmsdk.cpp, Line 165
ca4.exe 已触发了一个断点。

0x0FD72793 (appcrt140d.dll) (ca4.exe 中)处有未经处理的异常: 将一个无效参数传递给了将无效参数视为严重错误的函数。

程序片段如下:
bool PngData::ReadDataFromFile()
{
char png_header[8];
png_structp png_ptr;
png_infop info_ptr;
int width, height, rowBytes;
png_byte color_type;
png_byte bit_depth;
png_colorp palette;

FILE *file;
fopen_s(&file, m_filename.data(), "rb");
if (file == nullptr)
{
globalvars::gamelog.LogErr("Load picture failed: Cannot open picture file");
return false;
}

fread_s(png_header, sizeof(png_header), 8, 1, file);
if (png_sig_cmp((png_bytep)png_header, 0, 8))
{
globalvars::gamelog.LogErr("Load picture failed: Not a png file");
fclose(file);
return false;
}

png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info_ptr = png_create_info_struct(png_ptr);
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
globalvars::gamelog.LogErr("Load picture failed: Set jmp error");
fclose(file);
return false;
}

//I/O initialisation methods
png_init_io(png_ptr, file);
png_set_sig_bytes(png_ptr, 8); //Required!!!

png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_EXPAND, NULL); //运行至此时出错

width = info_ptr->width;
height = info_ptr->height;
unsigned char* rgba = new unsigned char[width * height * 4];
png_bytep* row_pointers = png_get_rows(png_ptr, info_ptr);

int pos = (width * height * 4) - (4 * width);
for (int row = 0; row < height; row++)
{
for (int col = 0; col < (4 * width); col += 4)
{
rgba[pos++] = row_pointers[row][col]; // red
rgba[pos++] = row_pointers[row][col + 1]; // green
rgba[pos++] = row_pointers[row][col + 2]; // blue
rgba[pos++] = row_pointers[row][col + 3]; // alpha
}
pos = (pos - (width * 4) * 2); //move the pointer back two rows
}

m_PictureSize.ImageWidth = width;
m_PictureSize.ImageHeight = height;
m_PixelData = rgba;

return true;
}
...全文
13869 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
水亦心 2017-05-30
  • 打赏
  • 举报
回复
我也出现这个问题了, 谁解出来了,求答案
Cai_chong 2017-03-21
  • 打赏
  • 举报
回复
楼主,这个问题你解决了吗?我遇到相似的问题了
vcf_reader 2015-02-24
  • 打赏
  • 举报
回复 2
其实这个问题可以这样理解:本来人家问你体重(好比需要的输入参数),你却告诉人家你家住在哪里(你实际输入的参数)。 这样当然会出错了。
赵4老师 2015-02-23
  • 打赏
  • 举报
回复
看不懂时双击下一行,直到能看懂为止
sunny晓美圆 2015-02-22
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止。
看不懂汇编指令啊
赵4老师 2015-02-22
  • 打赏
  • 举报
回复
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止。

64,666

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧