Hi,
I have been playing around with SDL for a few days, trying out some
examples and modifying it. But I am stuck at an error msg that happens
when I run the program:
$ gcc -Wall main.c -o teste -lSDL -lpthread
$ ./teste
Fatal signal: Segmentation Fault (SDL Parachute Deployed)
I saw on other messages in the mailing lists about putting a lot of
printfs to see if the functions return some error msg, I did it but even
so it does not show anything besides that message.
Can anyone help me out?
Thiago
//--------------------------------------------------------- The Code
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
SDL_Surface *screen, *scene, *doll;
// Vari?veis da personagem
SDL_Rect *pers;
short int doll_xvel = 0, doll_yvel = 0;
// Vari?veis de controle
SDL_Event event;
short int quit = 0;
int game_init()
{
if ((SDL_Init(SDL_INIT_VIDEO)) != 0)
{
fprintf(stderr, “N?o foi poss?vel inicializar o SDL: %s.\n”,
SDL_GetError());
exit(1);
}
if ((screen = SDL_SetVideoMode(800, 600, 24, SDL_HWSURFACE |
SDL_FULLSCREEN | SDL_DOUBLEBUF)) == 0)
fprintf(stderr, “Erro ao setar a v?deo: %s.\n”, SDL_GetError());
return(0);
}
int game_update()
{
// Carregando o cen?rio
if ((scene = SDL_LoadBMP(“cenario.bmp”)) == NULL)
fprintf(stderr, “Erro ao carregar o cen?rio: %s.\n”, SDL_GetError());
if ((SDL_BlitSurface(scene, NULL, screen, NULL)) < 0)
fprintf(stderr, “Erro ao blit o cen?rio: %s.\n”, SDL_GetError());
SDL_UpdateRect(screen, 0, 0, scene->w, scene->h);
// Carregando a personagem
if ((doll = SDL_LoadBMP(“pers.bmp”)) == NULL)
fprintf(stderr, “Erro ao carregar a personagem: %s.\n”, SDL_GetError());
pers->x = (screen->w / 2) - 80;
pers->y = (screen->h / 2) - 60;
pers->w = doll->w;
pers->h = doll->h;
if ((SDL_BlitSurface(doll, NULL, screen, pers)) < 0)
fprintf(stderr, “Erro ao blit a personagem: %s.\n”, SDL_GetError());
SDL_UpdateRect(screen, pers->x, pers->y, pers->w, pers->h);
return(0);
}
int game_quit()
{
SDL_FreeSurface(screen);
SDL_FreeSurface(scene);
SDL_FreeSurface(doll);
SDL_Quit();
return(0);
}
int main()
{
game_init();
game_update();
game_quit();
return(0);
}