JPEG support with ijg - getting access violation

前端 未结 7 1299
余生分开走
余生分开走 2021-01-06 12:00

I was recently trying to update my game to store graphics in compressed formats (JPEG and PNG).

Whilst I ended up settling on a different library, my initial attempt

7条回答
  •  死守一世寂寞
    2021-01-06 12:01

    Here is a workaround without having to rebuild the library: Make replacement I/O functions, as André Caron stated, but have nothing in them but the standard stdio functions.

    The code below I made in the past might help. It is written for libpng, but I believe it is easy to do the same in libjpeg.

    I added this to the code:

        png_set_write_fn (png_ptr,file,replwrite,replflush);
    

    Then created the replacement functions:

    void replwrite (png_structp png_ptr, png_bytep data, png_size_t length)
    {
        fwrite (data,1,length,(FILE*) png_get_io_ptr(png_ptr));
    }
    
    void replflush (png_structp png_ptr)
    {
        fflush ((FILE*) png_get_io_ptr(png_ptr));
    }
    

    It always works for me. What I'm actually doing is telling libpng, "Hey, don't use the write functions from the MSVCR that your .dll points to, use these ones, that come from the MSVCR I use in my program, fwrite and fflush". You see it's basically a compatibility issue.

    I hope this or something like this will solve the problem.

提交回复
热议问题