Sign in to follow this  
Hacktank

SDL, IMG_Load Always Returns NULL [solved]

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 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::getline(testfile,line);
std::cout << line << std::endl;

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this