#include <iostream>
#include <stdio.h>
#include <string>
#include "SDL/SDL.h"
usingnamespace std;
void handle_sdl_error(string message) {
printf("%s: %s\n", message.c_str(), SDL_GetError());
getchar();
SDL_Quit();
}
int main(int argc, char* args[]) {
SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;
SDL_Surface* image = NULL;
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
// Between here and ...
if (screen == NULL) {
handle_sdl_error("Could not set up screen");
return -1;
}
hello = SDL_LoadBMP("hello.bmp");
if(hello == NULL) {
handle_sdl_error("Could not load \"hello.bmp\" because");
return -1;
}
image = SDL_DisplayFormat(hello);
if(image == NULL) {
handle_sdl_error("Could not load \"hello.bmp\" because");
return -1;
}
SDL_FreeSurface(hello);
SDL_BlitSurface(image, NULL, screen, NULL);
SDL_Flip(screen);
// ... and here
cout << "Press Enter to quit." << endl;
cin.ignore(80, '\n');
SDL_FreeSurface(image);
SDL_Quit();
return 0;
}
If i just compile and run it, it just shows a black window.
But when i run it with gdb and set a breakpoint somewhere in the section i marked with my comments, no matter where, it will work and show me the loaded Bitmap.
To clarify this: I don't do anything in gdb, except setting the breakpoint, run the programm, continue on breakpoint, tada: BMP is shown.
Now i'm pretty curiuos how and why such a behavior is possible. Maybe some here can explain that to me. If you need any informations about my Environment, please ask.