Bonjour à tous,

je travaille sur un projet GTK dans le cadre de mes études cependant je rencontre un gros problème avec la destruction d'un widget et des events liés à ce widget.

J'obtiens une erreur de ce type :
"Gtk-CRITICAL **: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed" et en effet quand je regarde l'adresse de mon pointeur, il point vers NULL, cependant il est initialisé et la fenêtre s'ouvre dans un premier temps, je ne comprends donc pas pourquoi cela ne fonction pas.

Le .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
#include "winmain.h"
 
GtkWidget* allocationMainDialog()
{
    GtkWidget *new_ = NULL;
 
    //Allocation
    new_ = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
    //Configuration
    gtk_window_set_resizable(GTK_WINDOW(new_) , FALSE);
    gtk_window_position(GTK_WINDOW(new_) , GTK_WIN_POS_CENTER);
    gtk_window_set_title(GTK_WINDOW(new_) , "AIS Software");
 
    return new_;
}
 
guint* allocationGuintCallbackMain()
{
    guint *new_ = NULL;
 
    new_ = (guint*)malloc(2*sizeof(guint));
 
    return new_;
}
 
void layoutMainWindow(mainWindow* main_)
{
    //Add widgets in the right place
    //Menu
    gtk_table_attach_defaults(GTK_TABLE(main_->layout_),
                                    GTK_WIDGET(main_->menu_),0,4,0,1);
 
    //Map
    gtk_table_attach_defaults(GTK_TABLE(main_->layout_),
                                    GTK_WIDGET(main_->map_),0,3,1,6);
 
    //Speed
    gtk_table_attach_defaults(GTK_TABLE(main_->layout_),
                                    GTK_WIDGET(main_->speed_),3,4,1,2);
 
    //Compass
    gtk_table_attach_defaults(GTK_TABLE(main_->layout_),
                                    GTK_WIDGET(main_->compass_),3,4,2,3);
 
    //Label 1 leftDashboard
    gtk_table_attach_defaults(GTK_TABLE(main_->layout_),
                                    GTK_WIDGET(main_->labelsLeft_[0]),3,4,3,4);
 
    //Label 2 leftDashboard
    gtk_table_attach_defaults(GTK_TABLE(main_->layout_),
                                    GTK_WIDGET(main_->labelsLeft_[1]),3,4,4,5);
 
    //Label 3 leftDashboard
    gtk_table_attach_defaults(GTK_TABLE(main_->layout_),
                                    GTK_WIDGET(main_->labelsLeft_[2]),3,4,5,6);
 
    //Label 1 downDashboard
    gtk_table_attach_defaults(GTK_TABLE(main_->layout_),
                                    GTK_WIDGET(main_->labelsDown_[0]),0,1,6,7);
 
    //Label 2 downDashboard
    gtk_table_attach_defaults(GTK_TABLE(main_->layout_),
                                    GTK_WIDGET(main_->labelsDown_[1]),1,2,6,7);
 
    //Label 3 downDashboard
    gtk_table_attach_defaults(GTK_TABLE(main_->layout_),
                                    GTK_WIDGET(main_->labelsDown_[2]),2,3,6,7);
 
    //Label 1 downDashboard
    gtk_table_attach_defaults(GTK_TABLE(main_->layout_),
                                    GTK_WIDGET(main_->labelsDown_[3]),3,4,7,8);
 
    //Add layout to window
    gtk_container_add(GTK_CONTAINER(main_->window_), GTK_WIDGET(main_->layout_));
 
}
 
mainWindow* allocationMainWindow()
{
    mainWindow *main_ = NULL;
 
    //Dynamic allocation
    main_ = (mainWindow*)malloc(sizeof(mainWindow));
 
    //Allocation of each structure and widget
    main_->window_ = allocationMainDialog();
    main_->compass_ = allocationCompassWidget();
    main_->speed_ = allocationSpeedWidget();
    main_->labelsLeft_ = allocationLabelsWidgets(3);
    main_->map_ = allocationMap();
    main_->menu_ = allocationMenu();
    main_->layout_ = gtk_table_new(9,5,FALSE);
    main_->labelsDown_ = allocationLabelsWidgets(4);
    main_->gps_ = allocationGpsData();
    main_->callBackNb = allocationGuintCallbackMain();
 
    //Layout
    layoutMainWindow(main_);
 
    return main_;
}
 
void removeStructMainWindow(mainWindow *main_)
{
    //Close COM
    CloseCOM();
 
    //Remove event
    g_source_remove(main_->callBackNb[0]);
    g_source_remove(main_->callBackNb[1]);
 
    //Remove main widget
    gtk_widget_destroy(GTK_WIDGET(main_->window_));
 
 
    //Remove gps struct
    removeStructGpsData(main_->gps_);
 
    //Remove main pointer
    free(main_);
}
 
void eventUsb(mainWindow *main_)
{
    if(saveUsbGpsData(main_->gps_) == FALSE)
    {
        //Remove everything
        removeStructMainWindow(main_);
 
        //Launch com choice window
        launchNewWindow(2);
    }
}
 
void eventsMainWindow(mainWindow *main_)
{
    //Close the windows with the red 'X'
    g_signal_connect(main_->window_, "destroy", gtk_main_quit, NULL);
 
    //Update widget
    main_->callBackNb[0] = g_timeout_add(1000, (GSourceFunc)(updateTime), (gpointer)(main_->window_));
 
    //Redraw cairo window
    //Redraw compass each time
    g_signal_connect(main_->compass_, "expose-event",
                        G_CALLBACK(drawCompass), "100.00");
    gtk_widget_set_events (GTK_WIDGET(main_->compass_), GDK_ALL_EVENTS_MASK);
 
    //Redraw speed each time
    g_signal_connect(GTK_WIDGET(main_->speed_), "expose-event",
                        G_CALLBACK(drawSpeed), "40.00");
    gtk_widget_set_events (GTK_WIDGET(main_->speed_), GDK_ALL_EVENTS_MASK);
 
    //Redraw map each time
    g_signal_connect(GTK_WIDGET(main_->map_), "expose-event",
                        G_CALLBACK(drawMap), NULL);
    gtk_widget_set_events (GTK_WIDGET(main_->map_), GDK_ALL_EVENTS_MASK);
 
    //Read USB
    main_->callBackNb[1] = g_timeout_add(2000, (GSourceFunc)(eventUsb), (gpointer)(main_->gps_));
 
}
 
GtkWidget* launchMainWindow()
{
    mainWindow *main_ = NULL;
 
    //Allocation
    main_ = allocationMainWindow();
 
    //Open USB
    openUsbPort(10);
 
    //Events
    eventsMainWindow(main_);
 
    return main_->window_;
}
Le .h

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
#ifndef WINMAIN_H_INCLUDED
#define WINMAIN_H_INCLUDED
 
///*******************************INCLUDES***********************************///
 
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
 
#include "helpgtk.h"
#include "downdashboard.h"
#include "leftdashboard.h"
#include "map.h"
#include "menu.h"
#include "gpsdata.h"
#include "dialogcom.h"
 
///******************************STRUCTURES**********************************///
 
typedef struct mainWindow{
 
    //Gps DATA
    gpsData *gps_;
 
    //LeftDashboard
    GtkWidget *window_;
    GtkWidget **labelsLeft_;
    GtkWidget *compass_;
    GtkWidget *speed_;
 
    //Map
    GtkWidget *map_;
 
    //Menu
    GtkWidget *menu_;
 
    //DownDashboard
    GtkWidget **labelsDown_;
 
    //Layout table
    GtkWidget *layout_;
 
    //Callback function
    guint *callBackNb;
}mainWindow;
 
///*****************************PROTOTYPES***********************************///
 
GtkWidget* allocationMainDialog();
guint* allocationGuintCallbackMain();
void layoutMainWindow(mainWindow* main_);
mainWindow* allocationMainWindow();
void removeStructMainWindow(mainWindow *main_);
void eventUsb(mainWindow *main_);
void eventsMainWindow(mainWindow *main_);
GtkWidget* launchMainWindow();
 
#endif // WINMAIN_H_INCLUDED
Voilà, merci d'avance pour votre aide.