SDL_Surface returns a NULL

I’d first like to say hello to everyone before I start off. So…hello!

Note, this part is just me describing my story before this problem, so you don’t have to read.

I’ve used SDL 1.2 on a previous game of mine a year ago that turned out great ( for my first game with it of course ). After which I made the switch to SFML 1.6 because from reading the documentation of it I could have a more object-oriented library to work with. I enjoyed using it aside from certain limitations that SDL didn’t have. I would have probably kept using it due to me spending several days working on my own back-end for a game with it. After I finished days worth of work and wanted to start using what I made to create a level for the game however, I noticed problems such as the screen going black upon start-up when I used a custom view on the window. I checked my logic many times and saw no problems, so I thought it wise to post the relevant code to the SFML forums and describe my problem. Nobody could find a problem with my code, so they said to upgrade to SFML 2.0 and it might solve the issue. After spending another day or two re-writing my code with SFML 2.0 it
still wouldn’t work, and nobody else would respond to my posts so I gave up with SFML for the time being. Now I’m going back to SDL and am trying to re-write my back-end with it.

#End description.

I tried working through Lazy Foo’s SDL tutorials to get SDL set-up and tested before I start working with it. However, I couldn’t get an SDL_Surface to blit to the screen even with using his code to do so. Here’s the tutorial if it helps anyone:

The code compiled perfectly as well as linking, but my issue is that it never blitted to the screen as it did when I last did this tutorial a year ago. I thought I should check to see if perhaps the image was returning as NULL, which it was. My slightly changed code is here:

/This source code copyrighted by Lazy Foo’ Productions (2004-2012)
and may not be redestributed without written permission.

//Include SDL functions and datatypes
#include “SDL.h”

int main( int argc, char* args[] )
//The images
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;

//Start SDL

//Set up screen
screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );

//Load image
hello = SDL_LoadBMP( "hello.bmp" );

//Determins if the surface pointer isn't pointing to a memory
//loaded image.
if( hello == NULL )

	std::cout << "Image is null." << std::endl;


//Apply image to screen
SDL_BlitSurface( hello, NULL, screen, NULL );

//Update Screen
SDL_Flip( screen );

SDL_Delay( 2000 );

//Free the loaded image
SDL_FreeSurface( hello );

//Quit SDL

return 0;


It will not blit to the screen, and it does do the if loop I added into the original Lazy Foo code from lesson 1. I’m using SDL-1.2.14 on a Windows XP SP3 machine with my IDE and compiler being Visual Studio 2008 ( not Express ). Like most people posting their problems here say; I’d be grateful if someone could help me out.

Stupid question time, you do have a “hello.bmp” file in the same directory as the .exe?

If not you can easily create one in Paint.

I compiled and ran it without any problems, but I did have to create a BMP file for it to open.------------------------
The Legend of Edgar. A 2D platformer for Windows and Linux. (

Ah, I did forget to mention that. I do have a “hello.bmp” file in the same directory as the .exe file. It’s the same one from the tutorial actually. If it also helps in case someone thinks it could be a linker problem, here’s my linker order:


I did notice a particular warning that came up when compiling that may be helpful.

MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib ‘msvcrt.lib’ conflicts with use of other libs; use /NODEFAULTLIB:library

I tried not linking to the default library, but that created many problems. It seems the current SDL library conflicts with the default libraries. I’m not sure if that might be the problem, but that was the only other thing that showed up ( there were no errors or warnings beside that one ). Even with that warning, the window is created perfectly and I was able to use SDL for event management and tested keyboard presses just fine. I also tested the program on two Windows 7 machines and the same problem occurred.

Problem solved. I forgot to change my working directory for the program while I was debugging, so it couldn’t find the image in the original directory ( I had the new working directory somewhere else ).

Thanks for the help though!