#include "SDL/SDL.h"
int main(int argc, char** args)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
SDL_Surface* better = SDL_LoadBMP("test.bmp");
SDL_Rect offsets;
offsets.x = 30.5;
offsets.y = 30;
SDL_BlitSurface(better, NULL, screen, NULL);
Uint8* keystates = SDL_GetKeyState(NULL);
SDL_Event event;
bool quit = false;
int a = 0;
int b = 0;
int xslot[a];
int yslot[b];
while(quit == false)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
quit = true;
break;
}
}
xslot[a] = offsets.x;
yslot[b] = offsets.y;
a++;
b++;
if(keystates[SDLK_LEFT])
{
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
offsets.x -= 1;
}
if(keystates[SDLK_RIGHT])
{
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
offsets.x += 1;
}
if(keystates[SDLK_UP]) {
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
offsets.y -= 1;
}
if(keystates[SDLK_DOWN]) {
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
offsets.y += 1;
}
if(keystates[SDLK_LSHIFT])
{
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
offsets.x = xslot[a];
offsets.y = yslot[b];
a--;
b--;
}
SDL_BlitSurface(better, NULL, screen, &offsets);
SDL_Flip(screen);
}
SDL_FreeSurface(better);
SDL_FreeSurface(screen);
SDL_Quit();
}
Here's what the gdb gave me:
Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7b71ce7 in SDL_UpperBlit () from /usr/lib/x86_64-linux-gnu/libSDL-1.2.so.0
What's going on here?

New Topic/Question
Reply



MultiQuote





|