• 12
• 15
• 19
• 27
• 9

# SDL, IMG_Load Always Returns NULL [solved]

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

## 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:
SDLmain.lib
SDL.lib
SDL_image.lib
opengl32.lib
glu32.lib
gdi32.lib

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 on other sites
Have you set your debug working directory to the path of your assets?

##### 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::getline(testfile,line);	   std::cout << line << std::endl;    } else std::cout << "File cannot be opened" << std::endl;

##### 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 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.