The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Why IMG_Load_RW returns 0 on an iOS? How to fix it?
manifest


Joined: 16 Mar 2011
Posts: 9
Does anyone know why IMG_Load_RW return 0 when the following code running on an iphone simulator? If build and run this code on an MacOSX 10.6, it works well.

Code:
SDL_RWops *rw = SDL_RWFromFP(file, SDL_TRUE);
SDL_Surface *image = IMG_Load_RW(rw, 1); // on iphone simulator, image == 0


SDL_Error() returns "Invalid window"

Full code:
Code:
int main(int argc, char **argv) {
    if(SDL_Init(SDL_INIT_VIDEO) != 0)
        error("Unable to initialize SDL");
    atexit(SDL_Quit);
   
    SDL_Surface *screen = SDL_SetVideoMode(Width, Height, 16, 0 /* SDL_FULLSCREEN */);
    if(!screen)
        error("Unable to set video mode");
   
/*
   SDL_Surface *image = IMG_Load("bg.png");        //// works well anywhere
   if(!image)
      error("Unable to load image");
*/
   
    FILE *file = fopen("bg.png", "r");
    if(!file)
        error("Unable to read file");
    SDL_RWops *rw = SDL_RWFromFP(file, SDL_TRUE);
    SDL_Surface *image = IMG_Load_RW(rw, 1);        //// on iphone simulator, image == 0
    if(!image)
        error("Unable to load image");
   
    SDL_Rect src, dest;
    dest.x = dest.y = src.x = src.y = 0;
    dest.w = src.w = image->w;
    dest.h = src.h = image->h;
    SDL_BlitSurface(image, &src, screen, &dest);
    SDL_UpdateRect(screen, 0, 0, 0, 0);
    SDL_Delay(3000);
    SDL_FreeSurface(image);
   
    return 0;
}


--
Xcode 4, SDL 1.3
Why IMG_Load_RW returns 0 on an iOS? How to fix it?
Eric Wing
Guest

Are you using the ImageIO or UIImage backend? (Sam just grabbed my
ImageIO changes the other day. ImageIO is the recommended path moving
forward.)

UIImage has real technical limitations w.r.t. RWops. But since the
ImageIO backend is new to iOS, you may have discovered a new issue for
us.

-Eric

On 3/30/11, manifest wrote:
Quote:
Does anyone know why IMG_Load_RW return 0 when the following code running on
an iphone simulator? On MacOSX 10.6 it works well.


Code:
SDL_RWops *rw = SDL_RWFromFP(file, SDL_TRUE);
SDL_Surface *image = IMG_Load_RW(rw, 1); // on iphone simulator, image == 0



SDL_Error() returns "Invalid window"

Full code:

Code:
int main(int argc, char **argv) {
if(SDL_Init(SDL_INIT_VIDEO) != 0)
error("Unable to initialize SDL");
atexit(SDL_Quit);

SDL_Surface *screen = SDL_SetVideoMode(Width, Height, 16, 0 /*
SDL_FULLSCREEN */);
if(!screen)
error("Unable to set video mode");

/*
SDL_Surface *image = IMG_Load("bg.png"); //// works well anywhere
if(!image)
error("Unable to load image");
*/

FILE *file = fopen("bg.png", "r");
if(!file)
error("Unable to read file");
SDL_RWops *rw = SDL_RWFromFP(file, SDL_TRUE);
SDL_Surface *image = IMG_Load_RW(rw, 1); //// on iphone
simulator, image == 0
if(!image)
error("Unable to load image");

SDL_Rect src, dest;
dest.x = dest.y = src.x = src.y = 0;
dest.w = src.w = image->w;
dest.h = src.h = image->h;
SDL_BlitSurface(image, &src, screen, &dest);
SDL_UpdateRect(screen, 0, 0, 0, 0);
SDL_Delay(3000);
SDL_FreeSurface(image);

return 0;
}









--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Why IMG_Load_RW returns 0 on an iOS? How to fix it?
Vittorio G.
Guest

Hi Eric,
do you think you could briefly describe what difference will it make
to use ImageIO instead of UIImage?
Last time i messed with sdl_image imageio was available only on the
simulator while uiimage was available only on device; has the
situation changed?
thanks
Vittorio

On Wed, Mar 30, 2011 at 6:48 PM, Eric Wing wrote:
Quote:
Are you using the ImageIO or UIImage backend? (Sam just grabbed my
ImageIO changes the other day. ImageIO is the recommended path moving
forward.)

UIImage has real technical limitations w.r.t. RWops. But since the
ImageIO backend is new to iOS, you may have discovered a new issue for
us.

-Eric

On 3/30/11, manifest wrote:
Quote:
Does anyone know why IMG_Load_RW return 0 when the following code running on
an iphone simulator? On MacOSX 10.6 it works well.


Code:
SDL_RWops *rw = SDL_RWFromFP(file, SDL_TRUE);
SDL_Surface *image = IMG_Load_RW(rw, 1); // on iphone simulator, image == 0



SDL_Error() returns "Invalid window"

Full code:

Code:
int main(int argc, char **argv) {
    if(SDL_Init(SDL_INIT_VIDEO) != 0)
        error("Unable to initialize SDL");
    atexit(SDL_Quit);

    SDL_Surface *screen = SDL_SetVideoMode(Width, Height, 16, 0 /*
SDL_FULLSCREEN */);
    if(!screen)
        error("Unable to set video mode");

/*
      SDL_Surface *image = IMG_Load("bg.png");        //// works well anywhere
      if(!image)
              error("Unable to load image");
*/

    FILE *file = fopen("bg.png", "r");
    if(!file)
        error("Unable to read file");
    SDL_RWops *rw = SDL_RWFromFP(file, SDL_TRUE);
    SDL_Surface *image = IMG_Load_RW(rw, 1);        //// on iphone
simulator, image == 0
    if(!image)
        error("Unable to load image");

    SDL_Rect src, dest;
    dest.x = dest.y = src.x = src.y = 0;
    dest.w = src.w = image->w;
    dest.h = src.h = image->h;
    SDL_BlitSurface(image, &src, screen, &dest);
    SDL_UpdateRect(screen, 0, 0, 0, 0);
    SDL_Delay(3000);
    SDL_FreeSurface(image);

    return 0;
}









--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Re: Why IMG_Load_RW returns 0 on an iOS? How to fix it?
manifest


Joined: 16 Mar 2011
Posts: 9
Thank you for your fast answer, Eric. I used an UIImage backend.
I've built latest version of the SDL_image from repository and my problem was solved

Eric Wing wrote:
Are you using the ImageIO or UIImage backend? (Sam just grabbed my
ImageIO changes the other day. ImageIO is the recommended path moving
forward.)

UIImage has real technical limitations w.r.t. RWops. But since the
ImageIO backend is new to iOS, you may have discovered a new issue for
us.

-Eric

On 3/30/11, manifest wrote:
Quote:
Does anyone know why IMG_Load_RW return 0 when the following code running on
an iphone simulator? On MacOSX 10.6 it works well.


Code:
SDL_RWops *rw = SDL_RWFromFP(file, SDL_TRUE);
SDL_Surface *image = IMG_Load_RW(rw, 1); // on iphone simulator, image == 0



SDL_Error() returns "Invalid window"

Full code:

Code:
int main(int argc, char **argv) {
if(SDL_Init(SDL_INIT_VIDEO) != 0)
error("Unable to initialize SDL");
atexit(SDL_Quit);

SDL_Surface *screen = SDL_SetVideoMode(Width, Height, 16, 0 /*
SDL_FULLSCREEN */);
if(!screen)
error("Unable to set video mode");

/*
SDL_Surface *image = IMG_Load("bg.png"); //// works well anywhere
if(!image)
error("Unable to load image");
*/

FILE *file = fopen("bg.png", "r");
if(!file)
error("Unable to read file");
SDL_RWops *rw = SDL_RWFromFP(file, SDL_TRUE);
SDL_Surface *image = IMG_Load_RW(rw, 1); //// on iphone
simulator, image == 0
if(!image)
error("Unable to load image");

SDL_Rect src, dest;
dest.x = dest.y = src.x = src.y = 0;
dest.w = src.w = image->w;
dest.h = src.h = image->h;
SDL_BlitSurface(image, &src, screen, &dest);
SDL_UpdateRect(screen, 0, 0, 0, 0);
SDL_Delay(3000);
SDL_FreeSurface(image);

return 0;
}









--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Why IMG_Load_RW returns 0 on an iOS? How to fix it?
Eric Wing
Guest

On 3/30/11, Vittorio G. wrote:
Quote:
Hi Eric,
do you think you could briefly describe what difference will it make
to use ImageIO instead of UIImage?
Last time i messed with sdl_image imageio was available only on the
simulator while uiimage was available only on device; has the
situation changed?

That wasn't supposed to happen. The reason I wrote the UIImage backend
was that iOS originally didn't have ImageIO so we couldn't use it at
all. In iOS 4.0, ImageIO became available. According the the
statistics I've seen, around 90% of iOS users have upgraded to at
least 4.0 (current is 4.3 as of this writing) so I think it is safe to
make the default path now. It also solves nasty UIImage limitations
with RWops.

-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Why IMG_Load_RW returns 0 on an iOS? How to fix it?
Eric Wing
Guest

On 3/30/11, manifest wrote:
Quote:
Thank you for your fast answer, Eric. I used an UIImage backend. I've built
latest version of the SDL_image from repository and my problem was solved Smile


Thanks, I'm glad to hear ImageIO is working fine.

-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org