SDL_RWFromFile keeps returning NULL

Hello,
We are developing an image-manipulation app using latest stable releases
of SDL and SDL_image. On the Windows version, I have found a strange
problem regarding SDL_RWops.
Before loading an image, I verify its type like this:

if(NULL != strstr(path, “.jpg”)) {
SDL_RWops* rwop = SDL_RWFromFile(path, “rb”);
if(!rwop || !IMG_isJPG(rwop))
return false;
}

This works great but when I stress-tested the application (hundreds of
images) I found that
at some point SDL_RWFromFile will always return NULL on any filename I
throw at it even though the same filenames worked just fine before. None
of the files are deleted, moved or written to while the program runs and
by the way I don’t use any threads. The only cure for this problem is to
restart the app. Then SDL will give me a valid RWops again.

Now I’m looking at the SDL source and see that SDL_RWFromFile is
basically just a wrapper for fopen(). What could be the problem? If you
had any ideas that would be great.

I don’t know if this is the problem but could it be you are running out of
file handles?

You might want to make sure and use the equivalent of fclose() when you are
done with the file> ----- Original Message -----

From: sdl-bounces+atrix2=cox.net@libsdl.org
[mailto:sdl-bounces+atrix2=cox.net at libsdl.org] On Behalf Of Sebastian Posch
Sent: Tuesday, March 07, 2006 11:56 AM
To: sdl at libsdl.org
Subject: [SDL] SDL_RWFromFile keeps returning NULL

Hello,
We are developing an image-manipulation app using latest stable releases
of SDL and SDL_image. On the Windows version, I have found a strange
problem regarding SDL_RWops.
Before loading an image, I verify its type like this:

if(NULL != strstr(path, “.jpg”)) {
SDL_RWops* rwop = SDL_RWFromFile(path, “rb”);
if(!rwop || !IMG_isJPG(rwop))
return false;
}

This works great but when I stress-tested the application (hundreds of
images) I found that
at some point SDL_RWFromFile will always return NULL on any filename I
throw at it even though the same filenames worked just fine before. None
of the files are deleted, moved or written to while the program runs and
by the way I don’t use any threads. The only cure for this problem is to
restart the app. Then SDL will give me a valid RWops again.

Now I’m looking at the SDL source and see that SDL_RWFromFile is
basically just a wrapper for fopen(). What could be the problem? If you
had any ideas that would be great.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hello,
We are developing an image-manipulation app using latest stable releases
of SDL and SDL_image. On the Windows version, I have found a strange
problem regarding SDL_RWops.
Before loading an image, I verify its type like this:

if(NULL != strstr(path, “.jpg”)) {
SDL_RWops* rwop = SDL_RWFromFile(path, “rb”);
if(!rwop || !IMG_isJPG(rwop))
return false;
}

This works great but when I stress-tested the application (hundreds of
images) I found that
at some point SDL_RWFromFile will always return NULL on any filename I
throw at it even though the same filenames worked just fine before.

Are you closing the rwop you get back? You could be running out of file handles…

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

Hello,

I was indeed not closing the RWops.

Thanks.

Now I’m looking at the SDL source and see that SDL_RWFromFile is
basically just a wrapper for fopen(). What could be the problem? If you
had any ideas that would be great.

Are you closing the RWOps (that is, fclosing()) in the cases when you
can open it? I guess you’re running out of file descriptors.