Crash in png_set_read_fn() on Windows 7

0

I'm cross-compiling some C code for Windows 7 and linking to libpng12.dll found here. Unfortunately, the line below causes a crash (GDB says segmentation fault):

png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);

I'm not sure where to start to debug this--that function seems very straightforward and unrelated to the rest of the code. Top of the backtrace looks like this:

#0 0xabababab in ?? ()
#1 0x6cc556d1 in png_set_read_fn () from c:\...libpng12.dll
#2 0x6cc7a5d4 in png_libpng_ver () from c:\...libpng12.dll
#3 0x00000038 in ?? ()
#4 0x0028f928 in ?? ()

I guess #4 is png_create_read_struct(), since #5 is the function I call it from.

c
windows
gdb
libpng
asked on Stack Overflow Jul 17, 2012 by andyvn22

2 Answers

0

Please generate a core dump firstly by using ADplus or windbg etc.., and then look at the assembly code around the address of #0 (0xabababab ), also you can check the variable values with regards to those assembly. If you have the source code, you may have a good chance to understand the logic of why it crashes.

answered on Stack Overflow Jul 17, 2012 by Derui Si
0

Solved (unfortunately by trial & error) but just in case anyone else experiences this issue, it's caused by an incorrect version of zlib (in my case, too old). You can check for this quite easily at runtime:

fprintf(stderr, "   Compiled with libpng %s; using libpng %s.\n",
        PNG_LIBPNG_VER_STRING, png_libpng_ver);
fprintf(stderr, "   Compiled with zlib %s; using zlib %s.\n",
        ZLIB_VERSION, zlib_version);
answered on Stack Overflow Jul 18, 2012 by andyvn22

User contributions licensed under CC BY-SA 3.0