Bonjour, travaillant sur un projet de jeu du trésor. Celui-ci consiste en 3 coffre fermer, le joueur doit cliqué sur un des 3 coffres, 1 des 2 autres coffre qui est vide s'ouvre. Puis le joueur clique à nouveau sur les des 2 coffres restant et le jeu affiche ce dernier.
Je rencontre des erreurs que je n'arrive pas à corriger :

(tresor2:3080): Gtk-CRITICAL **: IA__gtk_widget_set_parent: assertion 'widget != parent' failed
Erreur de segmentation (core dumped)

Le problème étant que lors de la compilation aucune erreurs n'est détecté et c'est seulement lorsque je lance le programme qu'il m'affiche ces erreurs.

Voici mon code :
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include <stdlib.h>
#include <gtk/gtk.h>
#include <time.h>
 
// constantes
typedef enum {FERME=0,VIDE=1,PLEIN=2} etat_coffre_t;
typedef enum {DEBUT, PREMIER_CHOIX, GAGNE, PERDU} etat_jeu_t;
 
/*Declaration des variables globales*/
 
// bouton try again
GtkWidget* Recommencer=NULL;
 
// etat coffres et jeu
etat_coffre_t etat_coffre[3]={FERME,FERME,FERME};
etat_jeu_t etat_jeu= DEBUT ;
 
// endroit tresor
int case_tresor = 0;
 
// points
int defaites = 0;
int victoires = 0;
 
// Fenetre
GtkWidget* Fenetre = NULL;
 
// boutons coffres
GtkWidget* Button[3] = { NULL, NULL, NULL };
 
// images tresors
GdkPixbuf* pixbuf[3] = { NULL, NULL, NULL };
 
// label score instructions
GtkWidget* Score = NULL;
GtkWidget* Message = NULL;
 
// Déclaration des fonctions
void clic_bouton(int bouton);
void clic_bouton1();
void clic_bouton2();
void clic_bouton3();
void initialisation();
void coffre(int bouton, etat_coffre_t etat);
void scores_update();
 
// Définitions de fonctions
int main(int argc, char** argv)
{
	int etat_coffre, bouton ;
 
	// Initialisation gtk
	gtk_init(&argc, &argv);
 
	// Initialisation aleatoire
	srand(time(NULL));
 
	// Creation fenetre
	Fenetre = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(Fenetre), "Chasse au trésor");
	gtk_window_set_default_size(GTK_WINDOW(Fenetre), 400, 200);
	gtk_window_set_position(GTK_WINDOW(Fenetre), GTK_WIN_POS_CENTER_ALWAYS);
 
	// Declaration boite horizontale
	GtkWidget* HBox=NULL;
	GtkWidget* HBoxTresor=NULL;
	GtkWidget* VBoxTresor1=NULL;
 
	// Creation boutons
	for (bouton=0; bouton<3; bouton++)
	{
		Button[bouton ] = gtk_button_new();
	}
 
	// Creation des images  
	char * cheminsImages[3] =
	{"coffre_ferme.jpg",
	 "coffre_vide.jpg",
	 "coffre_plein.jpg"
	};
 
	for (etat_coffre=0; etat_coffre<3; etat_coffre=etat_coffre+1)
	{
		GdkPixbuf * pb = gdk_pixbuf_new_from_file(cheminsImages[etat_coffre], NULL);
    		pixbuf[etat_coffre] = gdk_pixbuf_scale_simple(pb, 100, 100, GDK_INTERP_NEAREST);
  	}
 
	// Creation des boites
	HBox = gtk_hbox_new(TRUE, 20);
	HBoxTresor = gtk_hbox_new(TRUE, 0);
	VBoxTresor1 = gtk_vbox_new(FALSE, 0);
 
	// Ajout boutons boite
	for (bouton=0; bouton<3; bouton++) 
	{
		gtk_box_pack_start(GTK_BOX(HBox), Button[bouton], FALSE, TRUE, 0);
	}
 
	// Label scores et instructions
	Score = gtk_label_new("Victoires: 0   Défaites : 0");
	gtk_box_pack_start(GTK_BOX(VBoxTresor1), Score, FALSE, FALSE, 0);
	Message = gtk_label_new("");
	gtk_box_pack_start(GTK_BOX(VBoxTresor1), Message, FALSE, FALSE, 0);
 
	// Bouton reinitialisation
	Recommencer = gtk_button_new_with_mnemonic("_Recommencer");
	gtk_box_pack_start(GTK_BOX(VBoxTresor1), Recommencer, FALSE, FALSE, 0);
 
	//conteneurs
	gtk_box_pack_start(GTK_BOX(HBoxTresor), HBoxTresor, TRUE, TRUE, 20);
	gtk_box_pack_start(GTK_BOX(VBoxTresor1), HBoxTresor, TRUE, TRUE, 20);
 
	gtk_container_add(GTK_CONTAINER(Fenetre), VBoxTresor1);
 
	// Affichage de tout
	gtk_widget_show_all(Fenetre);
	gtk_signal_connect(GTK_OBJECT(Fenetre), "destroy", G_CALLBACK(gtk_main_quit), NULL);
 
	// callbacks des coffres
	gtk_signal_connect(GTK_OBJECT(Button[0]), "clicked", G_CALLBACK(clic_bouton1), NULL);
	gtk_signal_connect(GTK_OBJECT(Button[1]), "clicked", G_CALLBACK(clic_bouton2), NULL);
	gtk_signal_connect(GTK_OBJECT(Button[2]), "clicked", G_CALLBACK(clic_bouton3), NULL);
 
	// callback bouton Recommencer
	gtk_signal_connect(GTK_OBJECT(Recommencer), "clicked", G_CALLBACK(initialisation), NULL);
 
	initialisation();
	gtk_main();
 
	return EXIT_SUCCESS;
}
 
// callbacks
void initialisation()
{
	// etat jeu
	etat_jeu = DEBUT;
 
	// coffre avec tresor
	case_tresor = (rand() % 3);
 
	// coffres fermés
	int bouton;
	for (bouton = 0; bouton<3; bouton = bouton + 1)
	{
		coffre(bouton, FERME);
	}
 
	// message
	gtk_label_set_text(GTK_LABEL(Message), "Choisissez un coffre");
 
	// désactivation du bouton try again
	gtk_widget_set_sensitive(Recommencer, FALSE);
}
 
void clic_bouton(int bouton)
{
	// Ouverture coffre deja ouvert
	if (etat_coffre[bouton] != FERME)
	{
		return;
	}
 
	// premier choix deja fait
	if (etat_jeu == PREMIER_CHOIX)
	{
		if (case_tresor == bouton) 
		{
			etat_jeu = GAGNE;
			coffre(bouton, PLEIN);
			victoires = victoires + 1;
			gtk_label_set_text(GTK_LABEL(Message), "Gagné");
		}
		else 
		{
			etat_jeu = PERDU;
			coffre(bouton, VIDE);
			defaites = defaites + 1;
			gtk_label_set_text(GTK_LABEL(Message), "Perdu");
		}
		gtk_widget_set_sensitive(Recommencer, TRUE);
		scores_update();
	}
 
	if (etat_jeu == DEBUT) 
	{
		etat_jeu = PREMIER_CHOIX;
		if (case_tresor != bouton)
		{
			// ouverture coffre vide
			int ahah = 0;
			for (ahah = 0; ahah<3; ahah = ahah + 1) 
			{
				if (ahah != bouton && ahah != case_tresor)
				{
					coffre(ahah, VIDE);
				}
			}
		}
		else 
		{
			// ouverture autre coffre
			int autre = (bouton + (rand() % 2) + 1) % 3;
			coffre(autre, VIDE);
		}
	}
}
 
void coffre(int bouton, etat_coffre_t etat)
{
	GtkWidget * image = gtk_image_new_from_pixbuf(pixbuf[etat]);
	gtk_button_set_image(GTK_BUTTON(Button[bouton]), image);
	etat_coffre[bouton] = etat ;
}
 
void scores_update()
{
	char message[100];
	sprintf(message, "Victoires : %d   Défaites : %d",victoires, defaites);
	gtk_label_set_text(GTK_LABEL(Score), message);
}
 
void clic_bouton1()
{
	 clic_bouton(0);
}
 
void clic_bouton2()
{
	clic_bouton(1);
}
 
void clic_bouton3()
{
	clic_bouton(2);
}
J'espère que j'obtiendrai assez rapidement une réponse car c'est urgent.