Jump to content
  • Advertisement
Sign in to follow this  

SDL, IMG_Load Always Returns NULL [solved]

This topic is 3217 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I am trying to load an image into my program that is using SDL, OpenGL, and SDL_image to load images. But for some reason IMG_Load() always returns a null pointer, no matter what. Even SDL_LoadBMP() returns a null pointer. I have the DLLs and the images in with my executable. Here is a codeblock:
    SDL_Surface *test = IMG_Load("test.png");

    std::cout << "test=" << test << " Reason: " << SDL_GetError() << std::endl;
Here is it's output:
test=00000000 Reason: Couldn't open test.png
If I try to load test.bmp with SDL_LoadBMP() I get the same results, with the obvious change of png to bmp. I am sure the pictures are there. I am using Microsoft Visual C++ 2008 Express Here are my libraries that i have linked:
Here is part of my globals.h:
#include "SDL.h"
#include "SDL_main.h"
#include "SDL_image.h"
#include "SDL_opengl.h"
#include <gl.h>
#include <glu.h>
#include <glext.h>
I am running release mode because debug mode causes link errors with "__imp___CrtDbgReportW". What am i doing wrong? Thank you. [Edited by - Hacktank on December 26, 2009 7:18:57 PM]

Share this post

Link to post
Share on other sites
I got debug mode to work, i was using the wrong runtime library. And yes, i set the working directory of debug mode to the folder the exe and other files are in, as well as release mode. Neither work.

I tried loading a text file in to see if the problem is global and it fails too.

std::ifstream testfile("test.txt");
std::string line;

if(testfile.is_open()) while(!testfile.eof()) {

std::cout << line << std::endl;

} else std::cout << "File cannot be opened" << std::endl;

Share this post

Link to post
Share on other sites
Pretty sure that your files you're trying to load are in the wrong place. Put them next to the project file, that's where the exe is going to be run from.

Share this post

Link to post
Share on other sites
Thank you very much, both of you. I got it working, i had the active directory set to where all my source files were, not my exe, fail. Its strange tho, a static reference to the file wouldn't work either, no matter tho.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!