Advertisement

Problem Loading PNGs with SDL_image on Windows

Started by July 08, 2012 06:37 PM
13 comments, last by szymczyk 12 years, 4 months ago
I run the release build from Windows Explorer. I also debug the debug build from Visual Studio. In both cases I place the PNGs and DLLs in the same directory as the executable. In both cases the PNG files do not load.
Mark Szymczyk
Author of Mac Game Programming and Xcode Tools Sensei
http://www.meandmark.com

The FILE pointer is NULL when I call fopen. I have tried to load five different images, and they all return NULL after calling IMG_Load. However, I have a text file in my game, and that file loads. It's just the PNG files that don't load. The text file is in the application directory, just like the PNG files.

There's only so many things that can go wrong here. Either the working directory is wrong (if you're only passing filename and not a full path), or there is something incorrect in the path being used. Maybe you are using single \ or something.
- What's the name of the file and it's full path on your computer? Does it use any non-english characters?
- What is the working directory when you attempt to open it?
- And what is the contents of the variable "filename" when you pass it to fopen?
Advertisement
I was able to load the files when running the game inside Visual Studio. Inside the project folder are three folders: Debug, Release, and the name of the project. Inside Visual Studio the working directory was the folder that matched the project name. Moving the PNGs and DLLs into the folder matching the name of the project allowed me to load the PNGs when debugging in Visual Studio.

I moved on to getting the release versions to work. I passed the full path to the PNG files in my code. The program crashed when I launched from Windows Explorer. When I stepped through the code in Visual Studio's debugger, the first two PNG files loaded, but the third one didn't.

I do not have any non-English characters in my path.

When I use fopen, I pass the name of the file. fopen returns a pointer whose address points to NULL when I pass the full path to the file as the filename.
Mark Szymczyk
Author of Mac Game Programming and Xcode Tools Sensei
http://www.meandmark.com

When I use fopen, I pass the name of the file. fopen returns a pointer whose address points to NULL when I pass the full path to the file as the filename.

This is not an uncommon issue. If you would please just tell:
1) What is the actual full path?
2) Please post the code you use when calling with fopen with the full path.
I found the cause of the release version crashing. After creating the OpenGL texture, I freed the memory of the SDL surface where I loaded the image file. Freeing the memory caused the crash.

Thanks for the help, everyone.
Mark Szymczyk
Author of Mac Game Programming and Xcode Tools Sensei
http://www.meandmark.com

This topic is closed to new replies.

Advertisement