提问者:小点点

C++/libpng-fclose()在调用png_write_png()后触发断点


null

int save_test_png()
{
    const string path = "D:\\test.png";
    const size_t X = 512, Y = 512;
    const size_t PIXEL_SIZE = 4;
    const size_t BIT_DEPTH = 8;

    FILE* image_file_ptr;
    png_structp png_ptr = nullptr;
    png_infop info_ptr = nullptr;
    png_byte** row_pointers = nullptr;

    int status = 0;

    if (fopen_s(&image_file_ptr, path.c_str(), "wb"))
    {
        return -1;
    }

    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (!png_ptr)
    {
        if (image_file_ptr)
        {
            fclose(image_file_ptr);
        }
        return -2;
    }

    info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr)
    {
        png_destroy_write_struct(&png_ptr, &info_ptr);
        if (image_file_ptr)
        {
            fclose(image_file_ptr);
        }
        return -3;
    }

    if (setjmp(png_jmpbuf(png_ptr)))
    {
        png_destroy_write_struct(&png_ptr, &info_ptr);
        if (image_file_ptr)
        {
            fclose(image_file_ptr);
        }
        return -4;
    }

    png_set_IHDR(png_ptr,
        info_ptr,
        X, Y,
        BIT_DEPTH,
        PNG_COLOR_TYPE_RGBA,
        PNG_INTERLACE_NONE,
        PNG_COMPRESSION_TYPE_DEFAULT,
        PNG_FILTER_TYPE_DEFAULT);

    row_pointers = static_cast<png_byte**>(png_malloc(png_ptr, Y * sizeof(png_byte*)));
    for (size_t y = 0; y < Y; y++)
    {
        png_byte* row = static_cast<png_byte*>(png_malloc(png_ptr, sizeof(png_byte) * X * PIXEL_SIZE));
        row_pointers[y] = row;
        for (size_t x = 0; x < X; x++)
        {
            *row++ = (x & 0x3F) << 2;                           // red
            *row++ = ((x & 0x1C0) >> 1) | ((y & 0x1C0) >> 4);   // green
            *row++ = (y & 0x3F) << 2;                           // blue
            *row++ = 0xFF;                                      // alpha
        }
    }

    png_init_io(png_ptr, image_file_ptr);
    png_set_rows(png_ptr, info_ptr, row_pointers);
    png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);

    status = 0;

    for (size_t y = 0; y < Y; y++)
    {
        png_free(png_ptr, row_pointers[y]);
    }
    png_free(png_ptr, row_pointers);
    png_destroy_write_struct(&png_ptr, &info_ptr);
    fclose(image_file_ptr);

    return status;
}

我使用正式版本附带的Visual Studio解决方案,从源代码处构建了libpng和zlib。该项目当前配置为Debug x64,libpng和zlib的。lib和。dll文件是按照手册中的建议在x64版本配置中构建的。“AppName.exe触发了一个断点”也会消失,如果我将正在处理的项目重新配置为版本x64。


共1个答案

匿名用户

当我将我的Debug x64配置链接到在Debug x64配置下生成的。lib文件,并将在相同配置下生成的。dll文件放置在可执行文件所在的项目的x64/Debug文件夹中时,“触发断点”异常消失了。

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(c++|libpng-fclose|调用|png_write_png|触发|断点)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?