SDL2_Image PNG segfault

Im attempting to add SDL 2.0 support into my app. Ive just built all of the SDL2
libraries with major issues or anything I couldnt work around.
When I run my debug build I get a segfault on the second png I attempt to load.
The segfault is the line where png_ptr is assigned.
I use SDL_image to decode and load files and then pass the raw data to opengl to
create textures.

SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)

/* Create the PNG loading context structure */
png_ptr = lib.png_create_read_struct(PNG_LIBPNG_VER_STRING,
                  NULL,NULL,NULL);
if (png_ptr == NULL){
    error = "Couldn't allocate memory for PNG file or incompatible PNG dll";
    goto done;
}

A few questions… What platform is this on? Are you using the same libpng you linked against? is SDL Image loading libpng dynamically? If so did it succeed in loading it?

libpng is one of those annoying libraries that if you don’t run against the same version your built against. It kind of blows up like you’ve seen. In general I always distribute the libpng version I compiled against OR I use something else entirely to handle my png loading (e.g. lodepng http://lodev.org/lodepng/ )On Jan 11, 2013, at 21:34 , Scott Smith wrote:

Im attempting to add SDL 2.0 support into my app. Ive just built all of the SDL2 libraries with major issues or anything I couldnt work around.
When I run my debug build I get a segfault on the second png I attempt to load. The segfault is the line where png_ptr is assigned.
I use SDL_image to decode and load files and then pass the raw data to opengl to create textures.

SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)

/* Create the PNG loading context structure */
png_ptr = lib.png_create_read_struct(PNG_LIBPNG_VER_STRING,
                  NULL,NULL,NULL);
if (png_ptr == NULL){
    error = "Couldn't allocate memory for PNG file or incompatible PNG dll";
    goto done;
}

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Edward Rudd
OutOfOrder.cc
Skype: outoforder_cc
317-674-3296

Not anymore since 1.5 where they made the ABI opaque. That’s also why
it filename was changed from libpng to libpng15, to prevent anybody
from accidentally linking an old program to a newer version that
breaks the ABI.

…what version of libpng does SDL_Image use?

2013/1/12, Edward Rudd :> A few questions… What platform is this on? Are you using the same libpng

you linked against? is SDL Image loading libpng dynamically? If so did it
succeed in loading it?

libpng is one of those annoying libraries that if you don’t run against the
same version your built against. It kind of blows up like you’ve seen. In
general I always distribute the libpng version I compiled against OR I use
something else entirely to handle my png loading (e.g. lodepng
http://lodev.org/lodepng/ )

On Jan 11, 2013, at 21:34 , Scott Smith wrote:

Im attempting to add SDL 2.0 support into my app. Ive just built all of
the SDL2 libraries with major issues or anything I couldnt work around.
When I run my debug build I get a segfault on the second png I attempt to
load. The segfault is the line where png_ptr is assigned.
I use SDL_image to decode and load files and then pass the raw data to
opengl to create textures.

SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)

/* Create the PNG loading context structure */
png_ptr = lib.png_create_read_struct(PNG_LIBPNG_VER_STRING,
                  NULL,NULL,NULL);
if (png_ptr == NULL){
    error = "Couldn't allocate memory for PNG file or incompatible PNG

dll";
goto done;
}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Edward Rudd
OutOfOrder.cc
Skype: outoforder_cc
317-674-3296

Not anymore since 1.5 where they made the ABI opaque. That’s also why
it filename was changed from libpng to libpng15, to prevent anybody
from accidentally linking an old program to a newer version that
breaks the ABI.

…what version of libpng does SDL_Image use?

That’s good to know about libpng… As for SDL_image, the version it
uses is.

Yes… :smiley: I’ve seen it linked against libpng12.so.0 and libpng.so.3
and libpng15.so.15.

And SDL_image can be build to dynamically load libpng or be linked
against it.

Though I still prefer lodepng, pnglite, or stb_image.c. as it makes
one less dependency to ship with a game.On 01/12/2013 06:22 PM, Sik the hedgehog wrote:

2013/1/12, Edward Rudd <@Edward_Rudd>:

A few questions… What platform is this on? Are you using the same libpng
you linked against? is SDL Image loading libpng dynamically? If so did it
succeed in loading it?

libpng is one of those annoying libraries that if you don’t run against the
same version your built against. It kind of blows up like you’ve seen. In
general I always distribute the libpng version I compiled against OR I use
something else entirely to handle my png loading (e.g. lodepng
http://lodev.org/lodepng/ )

On Jan 11, 2013, at 21:34 , Scott Smith wrote:

Im attempting to add SDL 2.0 support into my app. Ive just built all of
the SDL2 libraries with major issues or anything I couldnt work around.
When I run my debug build I get a segfault on the second png I attempt to
load. The segfault is the line where png_ptr is assigned.
I use SDL_image to decode and load files and then pass the raw data to
opengl to create textures.

SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)

/* Create the PNG loading context structure */
png_ptr = lib.png_create_read_struct(PNG_LIBPNG_VER_STRING,
                  NULL,NULL,NULL);
if (png_ptr == NULL){
    error = "Couldn't allocate memory for PNG file or incompatible PNG

dll";
goto done;
}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Edward Rudd
OutOfOrder.cc
Skype: outoforder_cc
317-674-3296


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Edward Rudd
OutOfOrder.cc
Skype: outoforder_cc
317-674-3296

Im running on opensuse 12.2 64 bit. Currently my current repos provide png12 and
png14. Im using dynamic loading.
I tried with just png14 installed, configure shows png14 being used for dynamic
linking. Same segfault.
I tried with png14 and png12 installed, configure shows png12 being used for
dynamic linking. Same segfault.
When i stepped through the code it did succeed in loading one image, but not the
second.
Ive never had any issue using this code with SDL 1.2 and SDL_image.

I really like to keep using SDL_image if there really is an issue then it should
be fixed. I dont think giving up and going to another provider is the best
option at this point.________________________________
From: urkle@outoforder.cc (Edward Rudd)
To: SDL Development List
Sent: Sat, January 12, 2013 5:41:56 PM
Subject: Re: [SDL] SDL2_Image PNG segfault

A few questions… What platform is this on? Are you using the same libpng you
linked against? is SDL Image loading libpng dynamically? If so did it succeed
in loading it?

libpng is one of those annoying libraries that if you don’t run against the same
version your built against. It kind of blows up like you’ve seen. In general I
always distribute the libpng version I compiled against OR I use something else
entirely to handle my png loading (e.g. lodepng http://lodev.org/lodepng/ )

On Jan 11, 2013, at 21:34 , Scott Smith wrote:

Im attempting to add SDL 2.0 support into my app. Ive just built all of the SDL2
libraries with major issues or anything I couldnt work around.

When I run my debug build I get a segfault on the second png I attempt to load.
The segfault is the line where png_ptr is assigned.
I use SDL_image to decode and load files and then pass the raw data to opengl to
create textures.

SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)

/* Create the PNG loading context structure */
png_ptr = lib.png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL,NULL,NULL);
if (png_ptr == NULL){
error = “Couldn’t allocate memory for PNG file or incompatible PNG
dll”;
goto done;
}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Edward Rudd
OutOfOrder.cc
Skype: outoforder_cc
317-674-3296

Just got it working, I didnt recompile the lib when I tried the combinations
from last night,

So libpng14 only, SDL_mixer rebuild and installed and it works as expected.

Thanks for having the answer from the beginning.________________________________
From: @Scott_Smith (Scott Smith)
To: SDL Development List
Sent: Mon, January 14, 2013 9:01:39 AM
Subject: Re: [SDL] SDL2_Image PNG segfault

Im running on opensuse 12.2 64 bit. Currently my current repos provide png12 and
png14. Im using dynamic loading.
I tried with just png14 installed, configure shows png14 being used for dynamic
linking. Same segfault.
I tried with png14 and png12 installed, configure shows png12 being used for
dynamic linking. Same segfault.
When i stepped through the code it did succeed in loading one image, but not the
second.
Ive never had any issue using this code with SDL 1.2 and SDL_image.

I really like to keep using SDL_image if there really is an issue then it should
be fixed. I dont think giving up and going to another provider is the best
option at this point.


From: urkle@outoforder.cc (Edward Rudd)
To: SDL Development List
Sent: Sat, January 12, 2013 5:41:56 PM
Subject: Re: [SDL] SDL2_Image PNG segfault

A few questions… What platform is this on? Are you using the same libpng you
linked against? is SDL Image loading libpng dynamically? If so did it succeed
in loading it?

libpng is one of those annoying libraries that if you don’t run against the same
version your built against. It kind of blows up like you’ve seen. In general I
always distribute the libpng version I compiled against OR I use something else
entirely to handle my png loading (e.g. lodepng http://lodev.org/lodepng/ )

On Jan 11, 2013, at 21:34 , Scott Smith wrote:

Im attempting to add SDL 2.0 support into my app. Ive just built all of the SDL2
libraries with major issues or anything I couldnt work around.

When I run my debug build I get a segfault on the second png I attempt to load.
The segfault is the line where png_ptr is assigned.
I use SDL_image to decode and load files and then pass the raw data to opengl to
create textures.

SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)

/* Create the PNG loading context structure */
png_ptr = lib.png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL,NULL,NULL);
if (png_ptr == NULL){
error = “Couldn’t allocate memory for PNG file or incompatible PNG
dll”;
goto done;
}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Edward Rudd
OutOfOrder.cc
Skype: outoforder_cc
317-674-3296