Bonjour, alors voilà j'ai décidé de programmer un petit Mario à l'aide de la bibliothèque SDL et tout fonctionnait très bien jusqu'à ce que j'ajoute le chargement de mon niveau... Mon niveau s'affiche parfaitement bien je peux naviguer mais lorsque je ferme la fenêtre, ça plante !

J'ai essayé d'isoler le problème en supprimant des morceaux de programme mais rien n'y fait je ne trouve pas d'où vient le problème. Voici mon code élagué au maximum...

Voici une image du jeu une fois compilé après élagage (le niveau n'est pas encore écrit ) :



Je sais seulement qu'il se situe au moment ou je sors de la fonction jouer()

jeu.c :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include <stdlib.h>
#include <stdio.h>
#include <SDL\SDL.h>
#include <SDL\SDL_image.h>
#include <SDL\SDL_ttf.h>
#include <FMOD/fmod.h>
#include <math.h>
 
#include "constantes.h"
#include "fichier.h"
#include "jeu.h"
 
int jouer(const int mode, SDL_Surface *ecran)
{
 
/*.................................................................................................................Déclarations variables SDL...*/
 
	SDL_Surface *grass[18] = {NULL}, *background = NULL;
	SDL_Rect position, positionBackground;
	Uint8 *keystates = NULL;
 
	SDL_Event event;
 
/*.................................................................................................................Déclarations variables...*/
 
	int direction = DROITE, fermer = OFF, i = 0, j = 0, scrolling = 0, bloc[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR] = {0}, tempsActuel = 0, tempsPrecedent = 0;
	char carte[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR] = {0}, pos[] = {0};
 
/*.................................................................................................................Définition et vérification des surfaces...*/
 
	grass[0] = IMG_Load("grass.png");
	grass[1] = IMG_Load("grass1.png");
	grass[2] = IMG_Load("grass2.png");
	grass[3] = IMG_Load("grass3.png");
	grass[4] = IMG_Load("grass4.png");
	grass[5] = IMG_Load("grass5.png");
	grass[6] = IMG_Load("grass6.png");
	grass[7] = IMG_Load("grass7.png");
	grass[8] = IMG_Load("grass8.png");
	grass[9] = IMG_Load("grass9.png");
	grass[10] = IMG_Load("grass10.png");
	grass[11] = IMG_Load("grass11.png");
	grass[12] = IMG_Load("grass12.png");
	grass[13] = IMG_Load("grass13.png");
	grass[14] = IMG_Load("grass14.png");
	grass[15] = IMG_Load("grass15.png");
	grass[16] = IMG_Load("grass16.png");
	grass[17] = IMG_Load("grass17.png");
	grass[18] = IMG_Load("grass18.png");
	background = IMG_Load("background.png");
	SDL_Verif(grass[0]);
	SDL_Verif(grass[1]);
	SDL_Verif(grass[2]);
	SDL_Verif(grass[3]);
	SDL_Verif(grass[4]);
	SDL_Verif(grass[5]);
	SDL_Verif(grass[6]);
	SDL_Verif(grass[7]);
	SDL_Verif(grass[8]);
	SDL_Verif(grass[9]);
	SDL_Verif(grass[10]);
	SDL_Verif(grass[11]);
	SDL_Verif(grass[12]);
	SDL_Verif(grass[13]);
	SDL_Verif(grass[14]);
	SDL_Verif(grass[15]);
	SDL_Verif(grass[16]);
	SDL_Verif(grass[17]);
	SDL_Verif(grass[18]);
	SDL_Verif(background);
 
	if(!creerCarte(carte, bloc))
		exit(EXIT_FAILURE);
 
/*.................................................................................................................Définitions des coordonnées...*/
 
	position.x = 0;
	position.y = 0;
	positionBackground.x = 0;
	positionBackground.y = 0;
 
/*.................................................................................................................Boucle principale...*/
 
	SDL_EnableKeyRepeat(100, 100);
 
	while(!fermer)
	{
		SDL_PollEvent(&event);
 
		keystates = SDL_GetKeyState(NULL);
 
		switch(event.type)
		{
			case SDL_QUIT:
				fermer = 1;
				break;
			case SDL_KEYDOWN:
				switch(event.key.keysym.sym)
				{
					case SDLK_ESCAPE:
						fermer = 1;
						break;
				}
				break;
		}
 
		tempsActuel = SDL_GetTicks();
 
        if (tempsActuel - tempsPrecedent > 5) /* Si 5 ms se sont écoulées depuis le dernier tour de boucle */
		{	
			if(keystates[SDLK_RIGHT])
			{
				if(scrolling > -TAILLE_BLOC * NB_BLOCS_LARGEUR + ecran->w)
					scrolling--;
			}
			if(keystates[SDLK_LEFT])
			{
				if(scrolling < 0)
					scrolling++;
			}
		}
		else /* Si ça fait moins de 5ms depuis le dernier tour de boucle, on endort le programme le temps qu'il faut */
		{
			SDL_Delay(5 - (tempsActuel - tempsPrecedent));
		}
 
/*.................................................................................................................Blit des surfaces...*/
 
		SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
 
		SDL_BlitSurface(background, NULL, ecran, &positionBackground);
		SDL_BlitLvl(carte, grass, ecran, scrolling);
 
		SDL_Flip(ecran);
 
	}
 
/*.................................................................................................................Libération des espaces dédiés aux surfaces...*/
 
	for (i = 0 ; i < 19 ; i++)
		SDL_FreeSurface(grass[i]);
	SDL_FreeSurface(background);
 
	return fermer;
}
 
void SDL_BlitLvl(char carte[][NB_BLOCS_HAUTEUR], SDL_Surface *grass[], SDL_Surface *ecran, int scrolling)
{
	int i = 0, j = 0;
	SDL_Rect position;
 
	for (i = 0 ; i < NB_BLOCS_LARGEUR ; i++)
		{
			for (j = 0 ; j < NB_BLOCS_HAUTEUR ; j++)
			{
				position.x = i * TAILLE_BLOC + scrolling;
				position.y = j * TAILLE_BLOC;
 
				switch (carte[i][j])
				{
					case 'a':
						SDL_BlitSurface(grass[0], NULL, ecran, &position);
						break;
					case 'b':
						SDL_BlitSurface(grass[1], NULL, ecran, &position);
						break;
					case 'c':
						SDL_BlitSurface(grass[2], NULL, ecran, &position);
						break;
					case 'd':
						SDL_BlitSurface(grass[3], NULL, ecran, &position);
						break;
					case 'e':
						SDL_BlitSurface(grass[4], NULL, ecran, &position);
						break;
					case 'f':
						SDL_BlitSurface(grass[5], NULL, ecran, &position);
						break;
					case 'g':
						SDL_BlitSurface(grass[6], NULL, ecran, &position);
						break;
					case 'h':
						SDL_BlitSurface(grass[7], NULL, ecran, &position);
						break;
					case 'i':
						SDL_BlitSurface(grass[8], NULL, ecran, &position);
						break;
					case 'j':
						SDL_BlitSurface(grass[9], NULL, ecran, &position);
						break;
					case 'k':
						SDL_BlitSurface(grass[10], NULL, ecran, &position);
						break;
					case 'l':
						SDL_BlitSurface(grass[11], NULL, ecran, &position);
						break;
					case 'm':
						SDL_BlitSurface(grass[12], NULL, ecran, &position);
						break;
					case 'n':
						SDL_BlitSurface(grass[13], NULL, ecran, &position);
						break;
					case 'o':
						SDL_BlitSurface(grass[14], NULL, ecran, &position);
						break;
					case 'p':
						SDL_BlitSurface(grass[15], NULL, ecran, &position);
						break;
					case 'q':
						SDL_BlitSurface(grass[16], NULL, ecran, &position);
						break;
					case 'r':
						SDL_BlitSurface(grass[17], NULL, ecran, &position);
						break;
 
				}
			}
		}
}
cette fonction utilise la fonction creerCarte() que voilà :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <stdlib.h>
#include <stdio.h>
#include <SDL\SDL.h>
#include <SDL\SDL_image.h>
#include <SDL\SDL_ttf.h>
#include <FMOD/fmod.h>
 
#include "constantes.h"
#include "jeu.h"
#include "fichier.h"
 
int creerCarte(char niveau[][NB_BLOCS_HAUTEUR], int bloc[][NB_BLOCS_HAUTEUR])
{
	FILE* fichier = NULL;
	char ligneFichier[NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1] = {0};
	int x = 0, y = 0;
 
	fichier = fopen("niveaux.lvl", "r");
	if (fichier == NULL)
	    return 0;
 
	fgets(ligneFichier, NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1, fichier);
 
	for (y = 0 ; y < NB_BLOCS_HAUTEUR ; y++)
	{
	    for (x = 0 ; x < NB_BLOCS_LARGEUR ; x++)
	    {
	        switch (ligneFichier[(y * NB_BLOCS_LARGEUR) + x])
	        {
	            case 'a':
	                niveau[x][y] = 'a';
					bloc[x][y] = PLEIN;
	                break;
	            case 'b':
	                niveau[x][y] = 'b';
					bloc[x][y] = PLEIN;
	                break;
	            case 'c':
		            niveau[x][y] = 'c';
					bloc[x][y] = PLEIN;
		            break;	
	            case 'd':
	                niveau[x][y] = 'd';
					bloc[x][y] = PLEIN;
	                break;
	            case 'e':
	                niveau[x][y] = 'e';
					bloc[x][y] = PLEIN;
	                break;
				case 'f':
	                niveau[x][y] = 'f';
					bloc[x][y] = PLEIN;
	                break;
	            case 'g':
	                niveau[x][y] = 'g';
					bloc[x][y] = PLEIN;
	                break;
	            case 'h':
		            niveau[x][y] = 'h';
					bloc[x][y] = PLEIN;
		            break;	
	            case 'i':
	                niveau[x][y] = 'i';
					bloc[x][y] = PLEIN;
	                break;
	            case 'j':
	                niveau[x][y] = 'j';
					bloc[x][y] = PLEIN;
	                break;
				case 'k':
	                niveau[x][y] = 'k';
					bloc[x][y] = PLEIN;
	                break;
	            case 'l':
	                niveau[x][y] = 'l';
					bloc[x][y] = PLEIN;
	                break;
	            case 'm':
		            niveau[x][y] = 'm';
					bloc[x][y] = PLEIN;
		            break;	
	            case 'n':
	                niveau[x][y] = 'n';
					bloc[x][y] = PLEIN;
	                break;
	            case 'o':
	                niveau[x][y] = 'o';
					bloc[x][y] = PLEIN;
	                break;
				case 'p':
	                niveau[x][y] = 'p';
					bloc[x][y] = PLEIN;
	                break;
	            case 'q':
	                niveau[x][y] = 'q';
					bloc[x][y] = PLEIN;
	                break;
	            case 'r':
		            niveau[x][y] = 'r';
					bloc[x][y] = PLEIN;
		            break;
			}
	    }
	}
 
	fclose(fichier);
 
	return 1;
}
Le menu principal fonctionne très bien je l'ai testé sans la fonction jouer().

Merci d'avance.