加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – libpng在png_write_into崩溃(Windows 10,VS2013,自建,所有

发布时间:2020-12-16 07:14:49 所属栏目:百科 来源:网络整理
导读:我在调用png_write_info时观察到由于libpng(1.6.20)中的访问冲突导致的崩溃.我从源代码构建了libpng(包括zlib 1.2.8),libpng源代码附带的png测试都没有任何错误.我可以确认在这些测试期间正在创建好的png文件. 我的程序的简单细分(直到崩溃的地方)看起来像这
我在调用png_write_info时观察到由于libpng(1.6.20)中的访问冲突导致的崩溃.我从源代码构建了libpng(包括zlib 1.2.8),libpng源代码附带的png测试都没有任何错误.我可以确认在这些测试期间正在创建好的png文件.

我的程序的简单细分(直到崩溃的地方)看起来像这样.为简单起见,我删除了所有错误和边界检查:

int main(int argc,char *argv[]) {
    char* filename = argv[1];
    png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING,NULL,NULL);
    png_infop info = png_create_info_struct(png);
    if (setjmp(png_jmpbuf(png)))
    {
        abort();
    }

    // Output is 16-bit depth,greyscale format.
    png_set_IHDR(
        png,info,127,16,PNG_COLOR_TYPE_GRAY,PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT,PNG_FILTER_TYPE_DEFAULT
    );

    // do the file stuff
    FILE *fp;
    errno_t error = fopen_s(&fp,filename,"wb");
    png_init_io(png,fp);
    png_write_info(png,info); // <-- crashes here with "access violation writing location ..."

谢谢你的帮助!

codeSourcerer

解决方法

好的,我得到了这个问题的答案,这要归功于此处发布的另一个问题:
libpng crashes on png_read_info()

在那里答案是:

If you don’t use the Visual Studio defaults your application must still be built with the default runtime option (/MD). If,for some reason,it is not then your application will crash inside libpng16.dll as soon as libpng tries to read from a file handle you pass in.

所以我重新编译了我的libpng,其属性 – >配置属性 – > C/C++ – >代码生成 – >运行时库设置为多线程DLL(/ MD)(不是调试版!!)
并为我的png-writer项目设置相同的内容.现在它正在工作,不再崩溃了.

干杯,codeSourcerer

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读