SDL -- Screen won't show my images

Hello. I decided to make a little animation program with c++ and SDL. basically a man runs when you keep the right button pressed, even with birds moving in the sky while you run. I use Code::Blocks for this. When I Build it and run it, it works fine. Yet whenever I try to open it from the project's /bin/Release executable file, a window pops up and disappears like a flash. If I run that from the terminal, it says there's been a Segmentation fault. Hmmm?

#ifdef __cplusplus
#include <cstdlib>
#else
#include <stdlib.h>
#endif
#include <SDL/SDL.h>

Uint8* keystate = SDL_GetKeyState(NULL);

SDL_Surface* screen = NULL;
SDL_Surface* back = NULL;
SDL_Surface* walker1 = NULL;
SDL_Surface* walker2 = NULL;
SDL_Surface* thingyup = NULL;
SDL_Surface* thingydown = NULL;
SDL_Surface* birds = NULL;

bool spr = true;
bool ite = false;

int main(int argc, char** argv) {

if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}

atexit(SDL_Quit);

SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16,
SDL_HWSURFACE|SDL_DOUBLEBUF);
if ( !screen )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
return 1;
}

SDL_Surface* back = SDL_LoadBMP("back.bmp");
SDL_Surface* walker1 = SDL_LoadBMP("walker1.bmp");
SDL_Surface* walker2 = SDL_LoadBMP("walker2.bmp");
SDL_Surface* birds = SDL_LoadBMP("birds.bmp");


SDL_Rect dstrect;
dstrect.x = 0;
dstrect.y = 75;
SDL_Rect sstrect;
sstrect.x = 0;
sstrect.y = 0;
SDL_Rect bstrect;
bstrect.x = 640;
bstrect.y = 0;

Uint32 colorkey = SDL_MapRGB( walker1->format, 255, 255, 255 );

SDL_SetColorKey( walker1, SDL_SRCCOLORKEY, colorkey );
SDL_SetColorKey( walker2, SDL_SRCCOLORKEY, colorkey );
SDL_SetColorKey( birds, SDL_SRCCOLORKEY, colorkey );

SDL_EnableKeyRepeat(100, 100);

SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));

SDL_BlitSurface(back, 0, screen, &sstrect);
SDL_BlitSurface(walker1, 0, screen, &dstrect);

SDL_Flip(screen);

bool done = false;
while (!done)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
done = true;
break;

case SDL_KEYDOWN:
{

if (event.key.keysym.sym == SDLK_ESCAPE) {

done = true;

}
if (event.key.keysym.sym == SDLK_RIGHT) {

if (spr == true) {

spr = false;
ite = true;

bstrect.x-=10;

SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));

SDL_BlitSurface(back, 0, screen, &sstrect);
SDL_BlitSurface(walker2, 0, screen, &dstrect);
SDL_BlitSurface(birds, 0, screen, &bstrect);

SDL_Flip(screen);

}
else if (ite == true) {

spr = true;
ite = false;

bstrect.x-=10;

if (bstrect.x == 0) {

bstrect.x = 640;

}
else;

SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));

SDL_BlitSurface(back, 0, screen, &sstrect);
SDL_BlitSurface(walker1, 0, screen, &dstrect);
SDL_BlitSurface(birds, 0, screen, &bstrect);

SDL_Flip(screen);

}
}

break;
}
}
}

}

SDL_FreeSurface(back);
SDL_FreeSurface(walker1);
SDL_FreeSurface(walker2);
SDL_FreeSurface(birds);

}

After looking at past projects, I thought of eliminating the colorkey part. No more segmentation faults, but then the only thing that would appear was a black screen. Yet I know SDL starts up correctly since there's no error output, and when I press the ESCAPE key, it closes as designed. So I'm assuming it's the bitmaps not being loaded or displayed somehow. I'd be really grateful if someone could help with this, it's very annoying. Also I'd like to know if possible WHY does the colorkey segment give a segmentation fault. It's something I can't really delete unless all my images are squares or rectangles wich is'nt normally the case. Thanks in advance! Oh, and I'm running Debian Testing, up to date, don't know the version name.
Topic archived. No new replies allowed.