haskell-game/sdl2-image

load fails while loading PNG images

eniac314 opened this issue · 7 comments

I get a sdlExceptionError = "Unsupported image format" while trying to open a png file with the load function. It works fine with gif files though.

I am using linux, ghc 7.10.2 and SDL2 2.0.3

Do you have libpng installed?

Try running initialize [InitPNG], does that work?

I installed libpng-dev via apt-get install, this time I get this error:
Exception: SDLCallFailed {sdlExceptionCaller = "SDL.Image.initialize", sdlFunction = "IMG_Init", sdlExceptionError = "PNG images are not supported"}

I'm not sure what causes this. This library's initialize is a very thin wrapper over IMG_Init, so I think you still might not have the needed dependencies? You could try using SDL2_image directly to see whether that works:

#include "SDL2/SDL.h"
#include "SDL2/SDL_image.h"

int main() {
  int wanted = IMG_INIT_PNG;
  int result = IMG_Init(wanted);
  if ((result & wanted) != wanted) {
    printf("IMG_Init: Failed to init.\n");
    printf("IMG_Init: %s\n", IMG_GetError());
  }
}

Compile like this: gcc image-test.c -o image-test -lSDL2 -lSDL2_image.

If then running it fails to load PNG support, there's a deeper issue.

running your program running returns:
IMG_Init: Failed to init.
IMG_Init: PNG images are not supported
I have libpng12-0 and libpng12-dev installed. Do I need something else?

Do you have libsdl2-image-dev installed? (I assume you're on Ubuntu or a similar system.)

It should pull in all needed dependencies, and be compiled to use them.

If you already have it, then I am at a loss. Not sure what else could have gone wrong.

I am on linux mint, and yes I have libsdl2-image-dev installed.
I will keep looking into it. Thanks for your help.

Reinstalling sdl2-Image from the source at https://www.libsdl.org/projects/SDL_image/ fixed the problem.