emscripten-ports / SDL2_image

Fork of https://github.com/libsdl-org/SDL_image
https://github.com/libsdl-org/SDL_image
Other
16 stars 11 forks source link

IMG_Init causes trouble #3

Open SafwatHalaby opened 9 years ago

SafwatHalaby commented 9 years ago
    int imgFlags = IMG_INIT_PNG;
    if( !( IMG_Init( imgFlags ) ) )
    {
        printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
        return false;
    }

This will always print the following message to the console

SDL_image could not initialize! SDL_image Error: PNG images are not supported

Interestingly, simply not calling IMG_Init makes everything work in Emscripten. Even more interestingly, whether one calls IMG_Init or not has no effect at all in NATIVE sdl2.

I don't know what to make of it. But at the very least, the Emscripten port should spit something like "You don't need to call IMG_Init" rather than just throw a confusing unrelated error.

kripken commented 9 years ago

I'm not sure at this point how we are building SDL image. I guess we aren't linking in libpng, and instead rely on browser decoding, which is asynchronous. I assume that's the reason for this confusion, but I'm not sure.

SafwatHalaby commented 9 years ago

PNG's are not the specific cause. Swap the flag with int imgFlags = IMG_INIT_WEBP and you'd get the same error, WEBP images are not supported, this is true for any flag.

SafwatHalaby commented 9 years ago

And by the way, all image types are in fact supported, as long as the user does not call IMG_init.

kripken commented 9 years ago

https://github.com/kripken/emscripten/pull/3831 addresses part of this, by giving an option to use libpng etc.