#1 Le 20/11/2008, à 14:17
- gregoire0
segmentation fault en langage c avec la sdl sous code block
Mon programme refuse de compiler et s'executer à la place j'ai un segmentation fault dans la console.
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <string.h>
int main(int argc, char *argv[])
{
int continuer = 1;
SDL_Surface *ecran = NULL,*fond = NULL,*texte=NULL;
SDL_Rect positionfond, positiontexte;
SDL_Event event;
positionfond.x = 0;
positionfond.y = 0;
positiontexte.x = 0;
positiontexte.y = ecran->h / 2 - texte->h / 2;
texte = SDL_LoadBMP("rien.bmp");
FILE* fichier = NULL;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
fond = SDL_LoadBMP("fond.bmp");
SDL_BlitSurface(fond, NULL, ecran, &positionfond);
texte = SDL_LoadBMP("texte.bmp");
SDL_BlitSurface(texte, NULL, ecran, &positionfond);
SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);
SDL_SetColorKey(texte, SDL_SRCCOLORKEY, SDL_MapRGB(texte->format, 255, 255, 255));
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
SDL_EnableKeyRepeat(10, 10); /* Activation de la répétition des touches */
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT: /* Si c'est un évènement QUITTER */
continuer = 0; /* On met le booléen à 0, donc la boucle va s'arrêter */
break;
case SDL_KEYUP:
switch(event.key.keysym.sym)
{
case SDLK_DOWN:
positiontexte.y++;
break;
case SDLK_RIGHT:
positiontexte.x++;
break;
case SDLK_LEFT:
positiontexte.x--;
break;
case SDLK_BACKSPACE:
texte = SDL_LoadBMP("rien.bmp");
positiontexte.x-=13;
break;
case SDLK_SPACE:
texte = SDL_LoadBMP("rien.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier,0, SEEK_END);
fprintf(fichier,"_");
fclose(fichier);
break;
case SDLK_RETURN:
fichier = fopen("test", "r+");
texte = SDL_LoadBMP("rien.bmp");
positiontexte.y+=13;
break;
case SDLK_a:
texte = SDL_LoadBMP("a.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"a");
fclose(fichier);
break;
case SDLK_b:
texte = SDL_LoadBMP("b.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"b");
fclose(fichier);
break;
case SDLK_c:
texte = SDL_LoadBMP("c.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"c");
fclose(fichier);
break;
case SDLK_d:
texte = SDL_LoadBMP("d.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"d");
fclose(fichier);
break;
case SDLK_e:
texte = SDL_LoadBMP("e.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"e");
fclose(fichier);
break;
case SDLK_f:
texte = SDL_LoadBMP("f.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"f");
fclose(fichier);
break;
case SDLK_g:
texte = SDL_LoadBMP("g.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"g");
fclose(fichier);
break;
case SDLK_h:
texte = SDL_LoadBMP("h.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"h");
fclose(fichier);
break;
case SDLK_i:
texte = SDL_LoadBMP("i.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"i");
fclose(fichier);
break;
case SDLK_j:
texte = SDL_LoadBMP("j.bmp");
positiontexte.x+=12;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"j");
fclose(fichier);
break;
case SDLK_k:
texte = SDL_LoadBMP("k.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"k");
fclose(fichier);
break;
case SDLK_l:
texte = SDL_LoadBMP("l.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"l");
fclose(fichier);
break;
case SDLK_m:
texte = SDL_LoadBMP("m.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"m");
fclose(fichier);
break;
case SDLK_n:
texte = SDL_LoadBMP("n.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"n");
fclose(fichier);
break;
case SDLK_o:
texte = SDL_LoadBMP("o.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"o");
fclose(fichier);
break;
case SDLK_p:
texte = SDL_LoadBMP("p.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"p");
fclose(fichier);
break;
case SDLK_q:
texte = SDL_LoadBMP("q.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"q");
fclose(fichier);
break;
case SDLK_r:
texte = SDL_LoadBMP("r.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"r");
fclose(fichier);
break;
case SDLK_s:
texte = SDL_LoadBMP("s.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"s");
fclose(fichier);
break;
case SDLK_t:
texte = SDL_LoadBMP("t.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"t");
fclose(fichier);
break;
case SDLK_u:
texte = SDL_LoadBMP("u.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"u");
fclose(fichier);
break;
case SDLK_v:
texte = SDL_LoadBMP("v.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"v");
fclose(fichier);
break;
case SDLK_w:
texte = SDL_LoadBMP("w.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"w");
fclose(fichier);
break;
case SDLK_x:
texte = SDL_LoadBMP("x.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"x");
fclose(fichier);
break;
case SDLK_y:
texte = SDL_LoadBMP("y.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"y");
fclose(fichier);
break;
case SDLK_z:
texte = SDL_LoadBMP("z.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"z");
fclose(fichier);
break;
case SDLK_1:
texte = SDL_LoadBMP("a.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"z");
fclose(fichier);
break;
default:
break;
}
default:
break;
}
SDL_Flip(ecran);
break;
}
SDL_FreeSurface(fond);
SDL_FreeSurface(texte);
SDL_Quit();
return EXIT_SUCCESS;
}
Ne faite pas attention au faute je suis dyslexique.
«Il était une fois un enfant de trois ans qui n’arrivait pas à apprendre à parler. À huit ans, il ne pouvait toujours pas lire. Ses enseignants pensaient qu’il était déficient. Il ne l’était pas. Albert Einstein avait des troubles d’apprentissage.»
Hors ligne
#2 Le 20/11/2008, à 14:38
- philou8237
Re : segmentation fault en langage c avec la sdl sous code block
Tu as le droit de nous mettre la sortie de gcc et de l'exécution de ton programme. C'est un peu nébuleux comme problème là.
Il ne compile pas ou il ne s'exécute pas ? Donne plus de détails, plutot que de nous jeter le source.
Hors ligne
#3 Le 20/11/2008, à 15:51
- rniamo
Re : segmentation fault en langage c avec la sdl sous code block
positiontexte.y = ecran->h / 2 - texte->h / 2;
ecran n'est pas à NULL sur cette ligne ?
< Quelques un des mes programmes | Cuisine Facile (pour les gourmands) | Fast MVC for PHP >
\ ^__^
\ (o o)\_______
(___)\ )\
Hors ligne
#4 Le 20/11/2008, à 15:55
- gregoire0
Re : segmentation fault en langage c avec la sdl sous code block
À vrai dire pour la sortie de gcc je sais pas trop de quoi ils s'agit, car je suis qu'un débutant donc...
Pour le fait de compiler ou de s'exécuter habituellement quant je clique sur le bouton compiler exécuter de code block le programme démarre, mais la ya juste une console qui s'affiche avec segmentation fault pour le reste j'en sais rien.
Ne faite pas attention au faute je suis dyslexique.
«Il était une fois un enfant de trois ans qui n’arrivait pas à apprendre à parler. À huit ans, il ne pouvait toujours pas lire. Ses enseignants pensaient qu’il était déficient. Il ne l’était pas. Albert Einstein avait des troubles d’apprentissage.»
Hors ligne
#5 Le 20/11/2008, à 16:00
- rniamo
Re : segmentation fault en langage c avec la sdl sous code block
t'as lu mon post ?
< Quelques un des mes programmes | Cuisine Facile (pour les gourmands) | Fast MVC for PHP >
\ ^__^
\ (o o)\_______
(___)\ )\
Hors ligne
#6 Le 20/11/2008, à 16:08
- gregoire0
Re : segmentation fault en langage c avec la sdl sous code block
t'as lu mon post ?
j'ai poster le message au moment ou t'on post est apparu donc je viens de le lire en retard.
le probleme à l'air de venir effectivment de cette ligne quant l'axe est à zero sa apparé et sa disparait rapidement donc je vai voir sa.
merci et désolé pour les fautes.
Ne faite pas attention au faute je suis dyslexique.
«Il était une fois un enfant de trois ans qui n’arrivait pas à apprendre à parler. À huit ans, il ne pouvait toujours pas lire. Ses enseignants pensaient qu’il était déficient. Il ne l’était pas. Albert Einstein avait des troubles d’apprentissage.»
Hors ligne
#7 Le 20/11/2008, à 16:11
- rniamo
Re : segmentation fault en langage c avec la sdl sous code block
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <string.h>
int main(int argc, char *argv[])
{
int continuer = 1;
SDL_Surface *ecran = NULL,*fond = NULL,*texte=NULL;
SDL_Rect positionfond, positiontexte;
SDL_Event event;
positionfond.x = 0;
positionfond.y = 0;
texte = SDL_LoadBMP("rien.bmp");
FILE* fichier = NULL;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
positiontexte.x = 0;
positiontexte.y = ecran->h / 2 - texte->h / 2;
fond = SDL_LoadBMP("fond.bmp");
SDL_BlitSurface(fond, NULL, ecran, &positionfond);
texte = SDL_LoadBMP("texte.bmp");
SDL_BlitSurface(texte, NULL, ecran, &positionfond);
SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);
SDL_SetColorKey(texte, SDL_SRCCOLORKEY, SDL_MapRGB(texte->format, 255, 255, 255));
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
SDL_EnableKeyRepeat(10, 10); /* Activation de la répétition des touches */
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT: /* Si c'est un évènement QUITTER */
continuer = 0; /* On met le booléen à 0, donc la boucle va s'arrêter */
break;
case SDL_KEYUP:
switch(event.key.keysym.sym)
{
case SDLK_DOWN:
positiontexte.y++;
break;
case SDLK_RIGHT:
positiontexte.x++;
break;
case SDLK_LEFT:
positiontexte.x--;
break;
case SDLK_BACKSPACE:
texte = SDL_LoadBMP("rien.bmp");
positiontexte.x-=13;
break;
case SDLK_SPACE:
texte = SDL_LoadBMP("rien.bmp");
positiontexte.x+=13;
break;
case SDLK_RETURN:
texte = SDL_LoadBMP("rien.bmp");
positiontexte.y+=13;
break;
case SDLK_a:
texte = SDL_LoadBMP("a.bmp");
positiontexte.x+=13;
break;
default:
break;
}
default:
break;
}
}
SDL_FreeSurface(fond);
SDL_FreeSurface(texte);
SDL_Quit();
return EXIT_SUCCESS;
}
ça ne fait pas ce que tu veux mais ça reste
< Quelques un des mes programmes | Cuisine Facile (pour les gourmands) | Fast MVC for PHP >
\ ^__^
\ (o o)\_______
(___)\ )\
Hors ligne
#8 Le 20/11/2008, à 17:59
- gregoire0
Re : segmentation fault en langage c avec la sdl sous code block
En fait j'ai compris que tout été dans le désordre et j'ai tout réorganiser mais je comprend toujour pas comment faire en sorte que sa reste afficher malgre le dernier code de rniamo qui foncsionne.
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <string.h>
int main(int argc, char *argv[])
{
int continuer = 1;
SDL_Surface *ecran = NULL,*fond = NULL,*texte=NULL;
SDL_Rect positionfond, positiontexte;
SDL_Event event;
FILE* fichier = NULL;
positionfond.x = 0;
positionfond.y = 0;
positiontexte.x = 0;
positiontexte.y = 0;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);
fond = SDL_LoadBMP("fond.bmp");
texte = SDL_LoadBMP("texte.bmp");
SDL_SetColorKey(texte, SDL_SRCCOLORKEY, SDL_MapRGB(texte->format, 255, 255, 255));
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
SDL_EnableKeyRepeat(10, 10); /* Activation de la répétition des touches */
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT: /* Si c'est un évènement QUITTER */
continuer = 0; /* On met le booléen à 0, donc la boucle va s'arrêter */
break;
case SDL_KEYUP:
switch(event.key.keysym.sym)
{
case SDLK_DOWN:
positiontexte.y++;
break;
case SDLK_RIGHT:
positiontexte.x++;
break;
case SDLK_LEFT:
positiontexte.x--;
break;
case SDLK_BACKSPACE:
texte = SDL_LoadBMP("rien.bmp");
positiontexte.x-=13;
break;
case SDLK_SPACE:
texte = SDL_LoadBMP("rien.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier,0, SEEK_END);
fprintf(fichier,"_");
fclose(fichier);
break;
case SDLK_RETURN:
texte = SDL_LoadBMP("rien.bmp");
positiontexte.y+=13;
break;
case SDLK_a:
texte = SDL_LoadBMP("a.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"a");
fclose(fichier);
break;
case SDLK_b:
texte = SDL_LoadBMP("b.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"b");
fclose(fichier);
break;
case SDLK_c:
texte = SDL_LoadBMP("c.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"c");
fclose(fichier);
break;
case SDLK_d:
texte = SDL_LoadBMP("d.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"d");
fclose(fichier);
break;
case SDLK_e:
texte = SDL_LoadBMP("e.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"e");
fclose(fichier);
break;
case SDLK_f:
texte = SDL_LoadBMP("f.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"f");
fclose(fichier);
break;
case SDLK_g:
texte = SDL_LoadBMP("g.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"g");
fclose(fichier);
break;
case SDLK_h:
texte = SDL_LoadBMP("h.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"h");
fclose(fichier);
break;
case SDLK_i:
texte = SDL_LoadBMP("i.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"i");
fclose(fichier);
break;
case SDLK_j:
texte = SDL_LoadBMP("j.bmp");
positiontexte.x+=12;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"j");
fclose(fichier);
break;
case SDLK_k:
texte = SDL_LoadBMP("k.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"k");
fclose(fichier);
break;
case SDLK_l:
texte = SDL_LoadBMP("l.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"l");
fclose(fichier);
break;
case SDLK_m:
texte = SDL_LoadBMP("m.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"m");
fclose(fichier);
break;
case SDLK_n:
texte = SDL_LoadBMP("n.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"n");
fclose(fichier);
break;
case SDLK_o:
texte = SDL_LoadBMP("o.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"o");
fclose(fichier);
break;
case SDLK_p:
texte = SDL_LoadBMP("p.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"p");
fclose(fichier);
break;
case SDLK_q:
texte = SDL_LoadBMP("q.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"q");
fclose(fichier);
break;
case SDLK_r:
texte = SDL_LoadBMP("r.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"r");
fclose(fichier);
break;
case SDLK_s:
texte = SDL_LoadBMP("s.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"s");
fclose(fichier);
break;
case SDLK_t:
texte = SDL_LoadBMP("t.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"t");
fclose(fichier);
break;
case SDLK_u:
texte = SDL_LoadBMP("u.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"u");
fclose(fichier);
break;
case SDLK_v:
texte = SDL_LoadBMP("v.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"v");
fclose(fichier);
break;
case SDLK_w:
texte = SDL_LoadBMP("w.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"w");
fclose(fichier);
break;
case SDLK_x:
texte = SDL_LoadBMP("x.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"x");
fclose(fichier);
break;
case SDLK_y:
texte = SDL_LoadBMP("y.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"y");
fclose(fichier);
break;
case SDLK_z:
texte = SDL_LoadBMP("z.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"z");
fclose(fichier);
break;
case SDLK_1:
texte = SDL_LoadBMP("a.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"z");
fclose(fichier);
break;
default:
break;
}
default:
break;
}
SDL_BlitSurface(fond, NULL, ecran, &positionfond);
SDL_BlitSurface(texte, NULL, ecran, &positiontexte);
SDL_Flip(ecran);
break;
}
SDL_FreeSurface(fond);
SDL_FreeSurface(texte);
SDL_Quit();
return EXIT_SUCCESS;
}
Dernière modification par gregoire0 (Le 20/11/2008, à 18:04)
Ne faite pas attention au faute je suis dyslexique.
«Il était une fois un enfant de trois ans qui n’arrivait pas à apprendre à parler. À huit ans, il ne pouvait toujours pas lire. Ses enseignants pensaient qu’il était déficient. Il ne l’était pas. Albert Einstein avait des troubles d’apprentissage.»
Hors ligne
#9 Le 20/11/2008, à 19:18
- rniamo
Re : segmentation fault en langage c avec la sdl sous code block
déjà test tes pointeurs après affectation :
exemple :
fond = SDL_LoadBMP("fond.bmp");
if (!fond)
exit(-1);
idem avec tes fichiers (les fopen)
PS : c'est possible d'avoir une version du code bien indentée ?
PS2 : et est-ce possible d'avoir une version complète (avec images) du projet ?
< Quelques un des mes programmes | Cuisine Facile (pour les gourmands) | Fast MVC for PHP >
\ ^__^
\ (o o)\_______
(___)\ )\
Hors ligne
#10 Le 20/11/2008, à 19:48
- gregoire0
Re : segmentation fault en langage c avec la sdl sous code block
déjà test tes pointeurs après affectation :
exemple :
fond = SDL_LoadBMP("fond.bmp"); if (!fond) exit(-1);
idem avec tes fichiers (les fopen)
PS : c'est possible d'avoir une version du code bien indentée ?
PS2 : et est-ce possible d'avoir une version complète (avec images) du projet ?
Je voi pas se que tu veux dire par bien indentée.
Pour la version avec image tu peux la télécharger içi http://www.megaupload.com/fr/?d=6GKFOMG6
Ne faite pas attention au faute je suis dyslexique.
«Il était une fois un enfant de trois ans qui n’arrivait pas à apprendre à parler. À huit ans, il ne pouvait toujours pas lire. Ses enseignants pensaient qu’il était déficient. Il ne l’était pas. Albert Einstein avait des troubles d’apprentissage.»
Hors ligne
#11 Le 20/11/2008, à 19:50
- rniamo
Re : segmentation fault en langage c avec la sdl sous code block
bien indenter ? je ne sais pas quel éditeur tu utilise mais en copiant collant il y a plein d'espaces blancs inutiles qui empêche la lisibilité.
< Quelques un des mes programmes | Cuisine Facile (pour les gourmands) | Fast MVC for PHP >
\ ^__^
\ (o o)\_______
(___)\ )\
Hors ligne
#12 Le 20/11/2008, à 20:40
- gregoire0
Re : segmentation fault en langage c avec la sdl sous code block
bien indenter ? je ne sais pas quel éditeur tu utilise mais en copiant collant il y a plein d'espaces blancs inutiles qui empêche la lisibilité.
C'était justement une erreur à cause de l'indention en fait j'avai un break à la fin de la boucle diffisilment visible.
Mon probleme est résolu voici la source modifier.
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <string.h>
int main(int argc, char *argv[])
{
int continuer = 1;
SDL_Surface *ecran = NULL,*fond = NULL,*texte=NULL;
SDL_Rect positionfond, positiontexte;
SDL_Event event;
FILE* fichier = NULL;
positionfond.x = 0;
positionfond.y = 0;
positiontexte.x = 0;
positiontexte.y = 0;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_WM_SetCaption("Gestion des évènements en SDL", NULL);
fond = SDL_LoadBMP("fond.bmp");
texte = SDL_LoadBMP("texte.bmp");
SDL_SetColorKey(texte, SDL_SRCCOLORKEY, SDL_MapRGB(texte->format, 255, 255, 255));
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
SDL_BlitSurface(fond, NULL, ecran, &positionfond);
SDL_EnableKeyRepeat(10, 10); /* Activation de la répétition des touches */
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT: /* Si c'est un évènement QUITTER */
continuer = 0; /* On met le booléen à 0, donc la boucle va s'arrêter */
break;
case SDL_KEYUP:
switch(event.key.keysym.sym)
{
case SDLK_DOWN:
positiontexte.y++;
break;
case SDLK_RIGHT:
positiontexte.x++;
break;
case SDLK_LEFT:
positiontexte.x--;
break;
case SDLK_BACKSPACE:
texte = SDL_LoadBMP("rien.bmp");
positiontexte.x-=13;
break;
case SDLK_SPACE:
texte = SDL_LoadBMP("rien.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier,0, SEEK_END);
fprintf(fichier,"_");
fclose(fichier);
break;
case SDLK_RETURN:
texte = SDL_LoadBMP("rien.bmp");
positiontexte.y+=13;
break;
case SDLK_a:
texte = SDL_LoadBMP("a.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"a");
fclose(fichier);
break;
case SDLK_b:
texte = SDL_LoadBMP("b.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"b");
fclose(fichier);
break;
case SDLK_c:
texte = SDL_LoadBMP("c.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"c");
fclose(fichier);
break;
case SDLK_d:
texte = SDL_LoadBMP("d.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"d");
fclose(fichier);
break;
case SDLK_e:
texte = SDL_LoadBMP("e.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"e");
fclose(fichier);
break;
case SDLK_f:
texte = SDL_LoadBMP("f.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"f");
fclose(fichier);
break;
case SDLK_g:
texte = SDL_LoadBMP("g.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"g");
fclose(fichier);
break;
case SDLK_h:
texte = SDL_LoadBMP("h.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"h");
fclose(fichier);
break;
case SDLK_i:
texte = SDL_LoadBMP("i.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"i");
fclose(fichier);
break;
case SDLK_j:
texte = SDL_LoadBMP("j.bmp");
positiontexte.x+=12;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"j");
fclose(fichier);
break;
case SDLK_k:
texte = SDL_LoadBMP("k.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"k");
fclose(fichier);
break;
case SDLK_l:
texte = SDL_LoadBMP("l.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"l");
fclose(fichier);
break;
case SDLK_m:
texte = SDL_LoadBMP("m.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"m");
fclose(fichier);
break;
case SDLK_n:
texte = SDL_LoadBMP("n.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"n");
fclose(fichier);
break;
case SDLK_o:
texte = SDL_LoadBMP("o.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"o");
fclose(fichier);
break;
case SDLK_p:
texte = SDL_LoadBMP("p.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"p");
fclose(fichier);
break;
case SDLK_q:
texte = SDL_LoadBMP("q.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"q");
fclose(fichier);
break;
case SDLK_r:
texte = SDL_LoadBMP("r.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"r");
fclose(fichier);
break;
case SDLK_s:
texte = SDL_LoadBMP("s.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"s");
fclose(fichier);
break;
case SDLK_t:
texte = SDL_LoadBMP("t.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"t");
fclose(fichier);
break;
case SDLK_u:
texte = SDL_LoadBMP("u.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"u");
fclose(fichier);
break;
case SDLK_v:
texte = SDL_LoadBMP("v.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"v");
fclose(fichier);
break;
case SDLK_w:
texte = SDL_LoadBMP("w.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"w");
fclose(fichier);
break;
case SDLK_x:
texte = SDL_LoadBMP("x.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"x");
fclose(fichier);
break;
case SDLK_y:
texte = SDL_LoadBMP("y.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"y");
fclose(fichier);
break;
case SDLK_z:
texte = SDL_LoadBMP("z.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"z");
fclose(fichier);
break;
case SDLK_1:
texte = SDL_LoadBMP("a.bmp");
positiontexte.x+=13;
fichier = fopen("test", "r+");
fseek(fichier, 0, SEEK_END);
fprintf(fichier,"z");
fclose(fichier);
break;
default:
break;
}
default:
break;
}
SDL_BlitSurface(texte, NULL, ecran, &positiontexte);
SDL_Flip(ecran);
}
SDL_FreeSurface(fond);
SDL_FreeSurface(texte);
SDL_Quit();
return EXIT_SUCCESS;
}
Dernière modification par gregoire0 (Le 20/11/2008, à 20:43)
Ne faite pas attention au faute je suis dyslexique.
«Il était une fois un enfant de trois ans qui n’arrivait pas à apprendre à parler. À huit ans, il ne pouvait toujours pas lire. Ses enseignants pensaient qu’il était déficient. Il ne l’était pas. Albert Einstein avait des troubles d’apprentissage.»
Hors ligne
#13 Le 20/11/2008, à 22:14
- rniamo
Re : segmentation fault en langage c avec la sdl sous code block
je venais te le dire.lol Sinon pense à libérer la mémoire entre 2 blit sinon...regarde le gestionnaire de mémoire, tu vas rire au bout de quelques itérations.
< Quelques un des mes programmes | Cuisine Facile (pour les gourmands) | Fast MVC for PHP >
\ ^__^
\ (o o)\_______
(___)\ )\
Hors ligne