Hello guys, I'm following the tutorials by LazyFoo but I tried to "design" the code by my own way... BUT (obviously) it crashes.
What am I doing wrong?
In case it is not clear, the code if ( !init ); tests the address of the init function and not the result of calling the init function as if ( !init() ); does. SDL_Quit; is a statement that just does nothing with the address of SDL_Quit, whereas SDL_Quit(); calls SDL_Quit.
If it isn't working, you should try using your debugger within your IDE and step through the problem.
In case it is not clear, the code if ( !init ); tests the address of the init function and not the result of calling the init function as if ( !init() ); does. SDL_Quit; is a statement that just does nothing with the address of SDL_Quit, whereas SDL_Quit(); calls SDL_Quit.
If it isn't working, you should try using your debugger within your IDE and step through the problem.
Oh God I'm so stupid. Haven't been programming for a while... thanks! Soooooooooooooooolved!
If your if statement is false you will return a null pointer.
Try this:
image = load_image("background.bmp");
if(image==NULL)std::cout<<"Failed to load image";
If that message is printed you need to fix the search path for your image.
No the problem was caused by those damned parenthesis..
Got another problem though. I've installed the SDL_image library BUT it cannot load my image... (tried to make it print errors in the "loading" function and it doesn't pop up any error).
You need to initialize SDL_Image by calling IMG_Init, before you can use any of SDL_Image's features.
Although both sport similar-looking APIs, always keep in mind that SDL and SDL_Image are completely separate libraries. For instance, to check any SDL-related errors, use SDL_GetError; to check any SDL_Image-related errors, use IMG_GetError.