Bonsoir, j'ai un segfault dans mon code :
void Game(SDL_Surface *screen, int *run)
{
/*Déclaration des variables*/
TabOfMap tabOfMap[iTab][jTab] = {0};
TTF_Font *typeface = TTF_OpenFont("angelina.ttf", 65);
SDL_Surface *background = initialiseBackground("map.png"), *text = NULL;
SDL_Color colorBlack = {0, 0, 0};
SDL_Rect posScore;
char score[20] = "";
Character character;
Res res;
Anim tabOfAnim[100];
int lastTimer = 0, timer = 0, firstTimerScore = 0, timerScore = 0, lastTimerScore = 0, i = 0, j = 0;
Input in;
/*Chargement génération aléatoire*/
srand(time(0));
/*Chargement du tableau d'animation*/
LoadTabAnim(tabOfAnim);
/*Attribution de valeurs aux variables*/
memset(&in,0,sizeof(in));
/*Information sur la résolution & co enregistré*/
GetResolution(&res);
/*Définition des propriétés des tiles de la carte*/
PropsMap(tabOfMap);
/*Initialisation du personnage principal*/
InitialiseCharacter(&character);
/*Premire initialisation du framerate*/
lastTimer = SDL_GetTicks();
firstTimerScore = SDL_GetTicks();
while (*run)
{
/*Gestion du clavier*/
UpdateEvents(&in);
timer = SDL_GetTicks();
/*Affichage du fond d'écran*/
DisplayBackground(screen, &background);
/*Deplacement du personnage principal*/
MoveCharacter(&character, tabOfMap, &in);
AnimCharacter(&in, &character, tabOfAnim);
GenerateHole(tabOfMap, tabOfAnim);
CreateAnimHole(tabOfMap, tabOfAnim);
/*Affichage des trous & Animation des trous*/
DisplayHole(screen, tabOfMap);
/*Affichage du personnage principal*/
DisplayCharacter(screen, &character);
SwitchBeforeHToHole(tabOfMap, tabOfAnim);
/*Score*/
sprintf(score, "%d", timer - firstTimerScore);
SDL_FreeSurface(text);
text = TTF_RenderText_Blended(typeface, score, colorBlack);
posScore.w = STANDARD_W_RES - text->w;
posScore.h = STANDARD_H_RES - text->h;
SDL_BlitSurface(text, NULL, screen, &posScore);
/*Gestion du framerate*/
timer = SDL_GetTicks() - lastTimer;
if (timer < 1000/FPS) SDL_Delay(1000/FPS - timer);
lastTimer = SDL_GetTicks(); /*Ré-initialisation*/
/*Flip de l'écran*/
SDL_Flip(screen);
/*Gestion de la fermeture du jeu*/
if(in.key[SDLK_ESCAPE] || in.quit)
{
*run = 0; /*Pour quitter le jeu partout*/
TTF_CloseFont(typeface);
SDL_FreeSurface(background); /*Free surface : background*/
for (i = 0; i < CRTI; i ++)
FreeAnim(&tabOfAnim[i]);
}
}
}
La ligne responsable est : text = TTF_RenderText_Blended(typeface, score, colorBlack);
Je ne comprend pas pourquoi...
