Bonjour,
j'ai une erreur segmentation, y'a surement une coquille quelque part mais je vois pas où.
J'ai 2 structures:
et une ptite fonction d'initialisation de tableau de données d'apres ces structures que voici:
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 typedef struct SDL_LedArray { SDL_Surface * p_surf_on; SDL_Surface * p_surf_off; SDL_Surface * p_surf; SDL_Rect rect; SDL_bool b_on; } SDL_LedArray; typedef struct SDL_Led { SDL_Rect size; SDL_Rect position; Uint32 i_speed; Uint16 i_led_tab_size; SDL_LedArray * led_array; } SDL_Led; SDL_Led * p_led_st;
Peut - être un blem au malloc ? Enfin je vois pas moi !
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 static SDL_Led * SDL_LedInit (Sint16 x, Sint16 y, Uint16 w, Uint16 h) { SDL_Led * p_led_st = NULL; Sint16 new_x = 0; Sint16 new_y = 0; int i = 0; int count = 0; /* ----- Allocation de la structure d'options ----- */ p_led_st = malloc (sizeof (SDL_Led *)); if (! p_led_st) { /* Erreur: impossible d'allouer la structure d'options. */ return NULL; } /* ----- */ /* ----- Allocation du tableau de leds ----- */ p_led_st->led_array = malloc (w * h * sizeof (SDL_LedArray *)); if (! p_led_st->led_array) { /* Erreur: impossible d'allouer le tableau de led. */ return NULL; } /* ----- */ /* ----- Initialisation de la structure d'options ----- */ p_led_st->size.w = w; p_led_st->size.h = h; p_led_st->position.x = x; p_led_st->position.y = y; p_led_st->i_speed = 30; p_led_st->i_led_tab_size = w * h; /* ----- */ /* ----- Initialisation du tableau de leds ----- */ new_x = p_led_st->position.x; new_y = p_led_st->position.y; for (i = 0; i < p_led_st->i_led_tab_size; i++) { p_led_st->led_array[i].p_surf_off = SDL_LoadBMP ("img/led-off.bmp"); p_led_st->led_array[i].p_surf_on = SDL_LoadBMP ("img/led-on.bmp"); p_led_st->led_array[i].p_surf = p_led_st->led_array[i].p_surf_off; p_led_st->led_array[i].rect.w = 15; p_led_st->led_array[i].rect.h = 15; p_led_st->led_array[i].rect.x = new_x; p_led_st->led_array[i].rect.y = new_y; p_led_st->led_array[i].b_on = SDL_FALSE; new_x = new_x + 15; count++; if (count == w) { count = 0; new_x = p_led_st->position.x; new_y = new_y + 15; } } /* ----- */ return p_led_st; }
Apparement le pbolème viendrais du chargement des SDL_Surface mais bon .... !
Merci d'avance
Partager