Bonjour,
j'ai fait un programme qui fonctionne mais pas trés clair. Valgrind ne me détecte pas d'erreur.
Je refais ce programme pour mieux le structurer en utilisant des structures initialisation dans fonction etc, je n'ai pas fini et valgrind me détecte déjà 141 erreurs. J'ai fait un petit programme qui reproduit cela.
Valgrind :
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 #include <SDL2/SDL.h> #include <stdio.h> #include <stdlib.h> #define LARGEUR 200 #define HAUTEUR 200 typedef struct { SDL_Window *fenetre; SDL_Renderer *rendu; SDL_Texture *cellule; SDL_Rect pos; } ComposantsJeu; int initialisation(ComposantsJeu *composant); SDL_Texture *cellules(ComposantsJeu *composant); int main(int argc, char *argv[]) { int statut = EXIT_FAILURE; ComposantsJeu composant = {0}; if(0 != initialisation(&composant)) goto Quit; SDL_RenderCopy(composant.rendu, composant.cellule, NULL, &composant.pos); SDL_RenderPresent(composant.rendu); SDL_Delay(3000); statut = EXIT_SUCCESS; Quit: if(NULL != composant.cellule) SDL_DestroyTexture(composant.cellule); if(NULL != composant.rendu) SDL_DestroyRenderer(composant.rendu); if(NULL != composant.fenetre) SDL_DestroyWindow(composant.fenetre); SDL_Quit(); return statut; } int initialisation(ComposantsJeu *composant) { if(0 != SDL_Init(SDL_INIT_VIDEO)) { fprintf(stderr, "Erreur SDL_Init : %s", SDL_GetError()); return -1; } if(0 != SDL_CreateWindowAndRenderer(LARGEUR, HAUTEUR, SDL_WINDOW_RESIZABLE, &composant->fenetre, &composant->rendu)) { fprintf(stderr, "Erreur SDL_CreateWindowAndRenderer : %s", SDL_GetError()); return -1; } if(0 != SDL_SetRenderDrawColor(composant->rendu, 242, 243, 244, 255)) { fprintf(stderr, "Erreur color: %s", SDL_GetError()); return -1; } if(0 != SDL_RenderClear(composant->rendu)) { fprintf(stderr, "Erreur SDL_render clear : %s", SDL_GetError()); return -1; } composant->pos.x = composant->pos.y = 95; composant->pos.w = composant->pos.h = 10; composant->cellule = cellules(composant); if(NULL == composant->cellule) return -1; return 0; } SDL_Texture *cellules(ComposantsJeu *composant) { SDL_Texture *texture = NULL; texture = SDL_CreateTexture(composant->rendu, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, composant->pos.w, composant->pos.h); if(NULL == texture) goto Erreur; if(0 != SDL_SetRenderTarget(composant->rendu, texture)) goto Erreur; if(0 != SDL_SetRenderDrawColor(composant->rendu, 21, 67, 96, 255)) /* bleu Belize hole*/ goto Erreur; if(0 != SDL_RenderFillRect(composant->rendu, NULL)) goto Erreur; if(0 != SDL_SetRenderTarget(composant->rendu, NULL)) goto Erreur; return texture; Erreur: fprintf(stderr, "Erreur SDL, Fonction cellules, fichier main.c : %s\n", SDL_GetError()); return NULL; }
Je compile avec gcc et l'option -g
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 ==2163== Memcheck, a memory error detector ==2163== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==2163== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==2163== Command: ./jeu ==2163== ==2163== Conditional jump or move depends on uninitialised value(s) ==2163== at 0xB357D5D: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0xB2B8838: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0xB2BA4F3: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0xB786527: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0xB69DF55: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0xB69D7FB: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0xB64C00A: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0x4E76A00: ??? (in /usr/lib/libSDL2-2.0.so.0.8.0) ==2163== by 0x4E719FE: ??? (in /usr/lib/libSDL2-2.0.so.0.8.0) ==2163== by 0x400F27: cellules (main.c:100) ==2163== by 0x400E4B: initialisation (main.c:75) ==2163== by 0x400C3A: main (main.c:25) ==2163== ==2163== Conditional jump or move depends on uninitialised value(s) ==2163== at 0xB35B5A7: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0xB2BA4CF: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0xB786527: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0xB69DF55: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0xB69D7FB: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0xB64C00A: ??? (in /usr/lib/dri/r600_dri.so) ==2163== by 0x4E76A00: ??? (in /usr/lib/libSDL2-2.0.so.0.8.0) ==2163== by 0x4E719FE: ??? (in /usr/lib/libSDL2-2.0.so.0.8.0) ==2163== by 0x400F27: cellules (main.c:100) ==2163== by 0x400E4B: initialisation (main.c:75) ==2163== by 0x400C3A: main (main.c:25) ==2163== ==2163== ==2163== HEAP SUMMARY: ==2163== in use at exit: 249,051 bytes in 2,058 blocks ==2163== total heap usage: 34,970 allocs, 32,912 frees, 11,128,723 bytes allocated ==2163== ==2163== LEAK SUMMARY: ==2163== definitely lost: 1,961 bytes in 26 blocks ==2163== indirectly lost: 3,781 bytes in 51 blocks ==2163== possibly lost: 0 bytes in 0 blocks ==2163== still reachable: 243,309 bytes in 1,981 blocks ==2163== suppressed: 0 bytes in 0 blocks ==2163== Rerun with --leak-check=full to see details of leaked memory ==2163== ==2163== For counts of detected and suppressed errors, rerun with: -v ==2163== Use --track-origins=yes to see where uninitialised values come from ==2163== ERROR SUMMARY: 7 errors from 2 contexts (suppressed: 5 from 1)
Tout est initialisé.
Auriez vous une idée ?
Merci
Partager