if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(sar);
return;
}
// Start reading info
png_init_io(png_ptr, sar);
png_set_sig_bytes(png_ptr, 8);
// The following line causes a crash!!
png_read_info(png_ptr, info_ptr);
fprintf(stderr,"We survived, thus far.\n");
}
Changed configuration to link with libpng.lib
Linked the program
Copied libpng12.dll and zlib1.dll to program directory
Ran program... it crashed!
Ran program in the debugger... it crashed on png_read_info somewhere in the bowels of KERNEL32.DLL.
What??? This is not supposed to happen. Does anyone have similar experiences? Thank you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, it's been nearly a year and a half since this post, but I'm having similar problems with libPng 1.2.8 on Visual Studio 2003 (on Windows XP SP2).
At first, I used the binary pack from GNUWIN32 and got the same crash (albeit, on png_read_png(), wich calls png_read_info() anyway).
Then, to see where the bug came from, I downloaded the sources and compiled them as a Debug DLL (compiled it using the included VC7.1 solution file). I copied the .lib and .dll file to my local project folder (and I'm linking against libpng13d.lib and zlib1d.lib).
Everything compiles perfectly but then, the Access violation I get is INSIDE png_read_info(). It's in :
png_read_info()
->png_read_data()
->((png_ptr->read_data_fn))(png_ptr, data, length); //line 31 of pngrio.c
->fread(data, (png_size_t)1, length, (png_FILE_p)png_ptr->io_ptr); // line 54 of pngrio.c
->_lock_str(stream); // line 75 of fread.c
->EnterCriticalSection( &(((_FILEX )pf)->lock) ); // line 235 of _file.c
And then, it pops up the error, while stalling on the first line of "_CRTIMP void * __cdecl malloc( size_t nSize)" (line 135 of dbgheap.c). That first instruction is a malloc:
" void *res = _nh_malloc_dbg(nSize, _newmode, _NORMAL_BLOCK, NULL, 0);"
At the time of debugging:
nSize = 108260096
_nwmode = 0
res = 0x00000001
This is the exact error message I get:
"Unhandled exception at 0x7c928fea in myApp.exe: 0xC0000005: Access violation writing location 0x00000010."
I'm pretty sure there is a simple fix for that. I've seen other people saying "just add all of libpng and zlib's source code in your project folder and compile"... But I don't want to include all this code, I would really prefer to use the .dll.
In any case, if any one has any comments/ideas, even if you tell me that the solution is to include the whole libpng tree in my project, don't hesitate...
Thanks!
--Yop83
My specs:
Pentium III 733
512 mb of ram
Nvidia GFX 5200
Windows XP SP2 PRO french
Visual Studio.Net 2003
libPNG 1.2.8
zlib 1.2.3
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I found someone on LibPNG's mailing who had the same problem.
The solution is relatively simple: just be sure that the project in which you are using LibPng is compiled with the same "Runtime Library" settings. I think that by default the lib is compiled in "/MD" (multi-threaded DLL) and a lot of projects are single threaded by default. This setting can be found in the project's property under C++/Code Generation (in VC7.1).
So, just insure that the setting are the same for both the library and your project and you should be all set.
This is something that really ought to be mentionned in the documents somewhere (I know that GnuWin32 does not make any documents, but maybe a quick readme with the installer?).
Anyway, thanks!
--Yop83
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For me libpng-1.2.5 seems to crash whenever png_read_info is called. Here's exactly what I did:
Downloaded and install zlib-1.2.1
Downloaded and install libpng-1.2.5
Removed "#include <unistd.h>" from zconf.h (bug!)
Compiled this using MSVC 6.0:
#include <stdio.h>
#include <stdlib.h>
#include <png.h>
void dummies();
int main(int argc, char* argv[])
{
printf("Trying to use the libpng library!\n");
dummies();
return 0;
}
void dummies()
{
FILE *sar;
png_byte header[8];
png_struct *png_ptr;
png_info *info_ptr;
// Locate the resource
sar = fopen("C:\\WINDOWS\\Profiles\\will\\My Documents\\My Pictures\\dennis.png","rb");
if (sar == NULL) return;
// Verify PNG integrity
fread(header, 1, 8, sar);
if (!png_check_sig(header, 8)) {
// File is not PNG
fclose(sar);
return;
}
// Create png structs
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
fclose(sar);
return;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
png_destroy_read_struct(&png_ptr, NULL, NULL);
fclose(sar);
return;
}
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(sar);
return;
}
// Start reading info
png_init_io(png_ptr, sar);
png_set_sig_bytes(png_ptr, 8);
// The following line causes a crash!!
png_read_info(png_ptr, info_ptr);
fprintf(stderr,"We survived, thus far.\n");
}
Changed configuration to link with libpng.lib
Linked the program
Copied libpng12.dll and zlib1.dll to program directory
Ran program... it crashed!
Ran program in the debugger... it crashed on png_read_info somewhere in the bowels of KERNEL32.DLL.
What??? This is not supposed to happen. Does anyone have similar experiences? Thank you.
Ok, it's been nearly a year and a half since this post, but I'm having similar problems with libPng 1.2.8 on Visual Studio 2003 (on Windows XP SP2).
At first, I used the binary pack from GNUWIN32 and got the same crash (albeit, on png_read_png(), wich calls png_read_info() anyway).
Then, to see where the bug came from, I downloaded the sources and compiled them as a Debug DLL (compiled it using the included VC7.1 solution file). I copied the .lib and .dll file to my local project folder (and I'm linking against libpng13d.lib and zlib1d.lib).
Everything compiles perfectly but then, the Access violation I get is INSIDE png_read_info(). It's in :
png_read_info()
->png_read_data()
->((png_ptr->read_data_fn))(png_ptr, data, length); //line 31 of pngrio.c
->fread(data, (png_size_t)1, length, (png_FILE_p)png_ptr->io_ptr); // line 54 of pngrio.c
->_lock_str(stream); // line 75 of fread.c
->EnterCriticalSection( &(((_FILEX )pf)->lock) ); // line 235 of _file.c
And then, it pops up the error, while stalling on the first line of "_CRTIMP void * __cdecl malloc( size_t nSize)" (line 135 of dbgheap.c). That first instruction is a malloc:
" void *res = _nh_malloc_dbg(nSize, _newmode, _NORMAL_BLOCK, NULL, 0);"
At the time of debugging:
nSize = 108260096
_nwmode = 0
res = 0x00000001
This is the exact error message I get:
"Unhandled exception at 0x7c928fea in myApp.exe: 0xC0000005: Access violation writing location 0x00000010."
I'm pretty sure there is a simple fix for that. I've seen other people saying "just add all of libpng and zlib's source code in your project folder and compile"... But I don't want to include all this code, I would really prefer to use the .dll.
In any case, if any one has any comments/ideas, even if you tell me that the solution is to include the whole libpng tree in my project, don't hesitate...
Thanks!
--Yop83
My specs:
Pentium III 733
512 mb of ram
Nvidia GFX 5200
Windows XP SP2 PRO french
Visual Studio.Net 2003
libPNG 1.2.8
zlib 1.2.3
You ever get this sorted? I am having the same issue.
Hi!
I solved my problem...
I found someone on LibPNG's mailing who had the same problem.
The solution is relatively simple: just be sure that the project in which you are using LibPng is compiled with the same "Runtime Library" settings. I think that by default the lib is compiled in "/MD" (multi-threaded DLL) and a lot of projects are single threaded by default. This setting can be found in the project's property under C++/Code Generation (in VC7.1).
So, just insure that the setting are the same for both the library and your project and you should be all set.
This is something that really ought to be mentionned in the documents somewhere (I know that GnuWin32 does not make any documents, but maybe a quick readme with the installer?).
Anyway, thanks!
--Yop83
Great! Thank you for your answer. It helps a lot.
Had the same problem
Thanks it helped a lot