SDL Window doesn't get created

Preface: Apologies for any poor formatting. This is my first post on this site. I did my best to take advantage of formatting options.


Hello, I am new to SDL. I have Windows 10 64 Bit, Visual Studio 2017 & installed the x86 VC Development binaries from here:

I am following LazyFoo’s guide and am on lesson 2 here:

I followed the first lesson with no issues. I got the Blue Window and console showing appropriately.
Now on Lesson 02 with displaying a .bmp image, I am getting another issue.

SDL or Windows is not creating a window for SDL to draw into. Here’s my code:
/This source code copyrighted by Lazy Foo’ Productions (2004-2015)
and may not be redistributed without written permission.

//Using SDL and standard IO
#include <SDL.h>
#include <stdio.h>

//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

//bool StartSDL();
//bool LoadAssets();
//void CloseSDL();

//The window we’ll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Surface* screenSurface = NULL;

SDL_Surface* HelloWorld = NULL;

bool StartSDL() {
bool success = true;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf(“SDL could not initialize! SDL_Error: %s\n”, SDL_GetError());
success = false;
//Create window
if (window == NULL)
printf(“Window could not be created! SDL_Error: %s\n”, SDL_GetError());
//Get window surface
screenSurface = SDL_GetWindowSurface(window);
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));

return success;


bool LoadAssets() {
bool success = true;

HelloWorld = SDL_LoadBMP("02_getting_an_image_on_the_screen/hello_world.bmp");
if (HelloWorld == NULL) {
	printf("Unable to load image %s! SDL Error: %s\n", "02_getting_an_image_on_the_screen/hellow_world.bmp", SDL_GetError());
	success = false;
return success;


void CloseSDL() {
HelloWorld = NULL;
window = NULL;



int main( int argc, char* args[] )

if (!StartSDL) {
	printf("Failed to start SDL.\n");
} /*else {
	if (!LoadAssets()) {
		printf("Failed to load assets. \n");
	} else {
		SDL_BlitSurface(HelloWorld, NULL, screenSurface, NULL);



return 0;


I commented out code that has nothing to do with what I’m trying to accomplish.
I tested with the code without comment syntax as well.

I followed along line by line with the downloadable code for lesson 02 from LazyFoo & I even double checked against the lesson 01 code to see if maybe something messed up. The window simply doesn’t appear.

Attached picture SDLhelp1 shows that Visual Studio is running and the console appears however in the task-bar you can clearly see that there is only 1 window for the tested program.

Attached picture SDLhelp2 shows that I have the .bmp image in the right folder for when I un-comment the code that tells SDL to show the image.

I haven’t the opportunity to test your code, so I cannot say if this is the sole issue, but in your main function, you use !StartSDL as the if conditional test, rather than !StartSDL().

This has the effect (I think…I’m still learning myself) of converting the function-pointer of StartSDL to an integer value for the conditional check, rather than executing StartSDL and getting its return value as you intended.

With this error, SDL is never initialized as StartSDL is never called. The conditional check allows the else to go ahead, at which your code attempts to use the uninitialized SDL functions.

1 Like