IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

GTK+ avec C & C++ Discussion :

[GTK+ C] Chronomètre : problème de structure +jouer un son


Sujet :

GTK+ avec C & C++

  1. #1
    Membre confirmé Avatar de acryline
    Profil pro
    Inscrit en
    Août 2006
    Messages
    200
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 200
    Par défaut [GTK+ C] Chronomètre : problème de structure +jouer un son
    Bonjour,

    j'ai fait un petit programme en GTK+ avec trois fichiers : main.c, fonctions.c et header.h (Source ci-dessous)
    Le programme fonctionne mais j'ai deux soucis :

    - si j'ai le malheur d'ajouter un champs, voire augmenter la taille d'un des tableaux de ma structure GADGET, mon programme ne démarre pas.. je pense à un problème de mémoire mais je n'arrive pas à le résoudre . Est ce du à l'appel périodique d'une fonction. J'ai toujours utilisé cette structure et jusqu'ici je n'ai jamais rencontré ce problème.

    - J'aurais aimé jouer un son quand le chrono arrive à 0. Comment faire ?

    Merci pour vos réponses.

    Exécutable pour Linux (sans runtime) compressé ZIP
    header.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
     
    #ifndef DEF_CHRONO
    #define DEF_CHRONO
     
    #define LARGEUR     150
    #define HAUTEUR     150
     
    //structures
    typedef struct GADGET GADGET;
     struct GADGET
     {
       GtkWidget * fenetre[1];
       GtkWidget * VBox[1];
       GtkWidget * HBox[2];
       GtkWidget * bouton[4];
       GtkWidget * entree[3];
       time_t temps;
       gboolean chrono; //valeur retournée dans la fct° périodique
       guint test; //numéro du processus
     };
     
     //fonctions
     void cadreFenetre(GADGET *);
     void accueil(GADGET *);
     void chrono(GtkWidget *, gpointer);
     void chrono_start(GtkWidget *, gpointer);
     void chrono_stop(GtkWidget *, gpointer);
     void retour_accueil(GtkWidget *, gpointer);
     void quitter(GtkWidget *, gpointer);
     void decompte(GtkWidget *, gpointer);
     gboolean  calcul_temps (gpointer);
     void decompte_start(GtkWidget *, gpointer);
     gboolean  calcul_decompte (gpointer);
     
    #endif
    main.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
    #include <stdlib.h>
    #include <gtk/gtk.h>
    #include <time.h>
    #include "header.h"
     
    int main(int argc,char **argv)
    {
        /* Declaration du widget */
        GADGET gadget;
     
        gtk_init(&argc,&argv);
     
        /* Creation de la fenetre */
        gadget.fenetre[0] = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        cadreFenetre(&gadget);
        accueil(&gadget);
       /* Affichage de la fenetre */
     
        gtk_main();
     
        return EXIT_SUCCESS;
    }
    fonctions.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
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
     
    #include <stdlib.h>
    #include <gtk/gtk.h>
    #include <time.h>
    #include "header.h"
     
    //Dessiner la fenêtre principale
    void cadreFenetre(GADGET *p_gadget)
    {
        /* Definition de la position */
        gtk_window_set_position(GTK_WINDOW(p_gadget->fenetre[0]), GTK_WIN_POS_CENTER);
        /* Taille de la Fenêtre */
        gtk_window_set_default_size  (GTK_WINDOW(p_gadget->fenetre[0]),LARGEUR,HAUTEUR );
        /* barre des titres*/
        gtk_window_set_decorated (GTK_WINDOW(p_gadget->fenetre[0]),TRUE);
        /*Icone*/
        //gtk_window_set_default_icon_from_file(ADRESSE_ICONE,NULL);
        /*espace de 1 autour de la fenêtre*/
        gtk_container_set_border_width(GTK_CONTAINER(p_gadget->fenetre[0]),1 );
    }
     
    //choix chrono ou décompte
    void accueil(GADGET *p_gadget)
    {
      if (p_gadget->VBox[0])
      {
          gtk_widget_destroy(p_gadget->VBox[0]);
      }
      p_gadget->VBox[0]=gtk_vbox_new(TRUE,0);
      gtk_container_add (GTK_CONTAINER(p_gadget->fenetre[0]),p_gadget->VBox[0]);
      p_gadget->bouton[0]=  gtk_button_new_with_label("Chronomètre") ;
      p_gadget->bouton[1]=  gtk_button_new_with_label("Décompte") ;
      gtk_box_pack_start(GTK_BOX(p_gadget->VBox[0]),p_gadget->bouton[0],TRUE,TRUE,0);
      gtk_box_pack_start(GTK_BOX(p_gadget->VBox[0]),p_gadget->bouton[1],TRUE,TRUE,0);
      gtk_widget_show_all(p_gadget->fenetre[0]);
     
      g_signal_connect(G_OBJECT(p_gadget->bouton[0]), "clicked", G_CALLBACK(chrono), (gpointer)p_gadget);
      g_signal_connect(G_OBJECT(p_gadget->bouton[1]), "clicked", G_CALLBACK(decompte), (gpointer)p_gadget);
      g_signal_connect(G_OBJECT(p_gadget->fenetre[0]), "destroy", G_CALLBACK(quitter), NULL);
     
    }
     
    //callback du bouton chronomètre --> affichage des GtkEntry et boutons
    void chrono(GtkWidget *p_Bouton, gpointer data)
    {
        GADGET *p_gadget=NULL;
        p_gadget=(GADGET*)data;
        GtkWidget *label;
        gchar buf[32];
     
        gtk_widget_destroy(p_gadget->VBox[0]);
        p_gadget->VBox[0]=gtk_vbox_new(TRUE,0);
        gtk_container_add (GTK_CONTAINER(p_gadget->fenetre[0]),p_gadget->VBox[0]);
        //les boutons
        p_gadget->bouton[0]=  gtk_button_new_with_label("Lancer") ;
        p_gadget->bouton[1]=   gtk_button_new_with_label("Stop") ;
        p_gadget->bouton[2]=   gtk_button_new_with_label("Accueil") ;
        p_gadget->bouton[3]=   gtk_button_new_with_label("Quitter") ;
     
        //les gtkEntry
        p_gadget->entree[0]=gtk_entry_new();
        gtk_entry_set_width_chars(GTK_ENTRY(p_gadget->entree[0]),3);
        gtk_editable_set_editable(GTK_EDITABLE(p_gadget->entree[0]),FALSE);
        p_gadget->entree[1]=gtk_entry_new();
        gtk_entry_set_width_chars(GTK_ENTRY(p_gadget->entree[1]),3);
        gtk_editable_set_editable(GTK_EDITABLE(p_gadget->entree[1]),FALSE);
        p_gadget->entree[2]=gtk_entry_new();
        gtk_entry_set_width_chars(GTK_ENTRY(p_gadget->entree[2]),3);
        gtk_editable_set_editable(GTK_EDITABLE(p_gadget->entree[2]),FALSE);
     
        p_gadget->HBox[0]=gtk_hbox_new(FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->VBox[0]),p_gadget->HBox[0],FALSE,FALSE,0);
     
        //entrer les widgets
        label=gtk_label_new("              ");
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[0]),label,FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[0]),p_gadget->entree[0],FALSE,FALSE,0);
        label=gtk_label_new(":");
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[0]),label,FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[0]),p_gadget->entree[1],FALSE,FALSE,0);
        label=gtk_label_new(":");
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[0]),label,FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[0]),p_gadget->entree[2],FALSE,FALSE,0);
     
        p_gadget->HBox[1]=gtk_hbox_new(TRUE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->VBox[0]),p_gadget->HBox[1],FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[1]),p_gadget->bouton[0],FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[1]),p_gadget->bouton[1],FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[1]),p_gadget->bouton[2],FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[1]),p_gadget->bouton[3],FALSE,FALSE,0);
        //texte des GtkEntry
         sprintf(buf,"%d",0);
         gtk_entry_set_text(GTK_ENTRY(p_gadget->entree[0]),buf);
         sprintf(buf,"%d",0);
         gtk_entry_set_text(GTK_ENTRY(p_gadget->entree[1]),buf);
         sprintf(buf,"%d",0);
         gtk_entry_set_text(GTK_ENTRY(p_gadget->entree[2]),buf);
     
        g_signal_connect(G_OBJECT(p_gadget->bouton[0]), "clicked", G_CALLBACK(chrono_start), (gpointer)p_gadget);
        g_signal_connect(G_OBJECT(p_gadget->bouton[1]), "clicked", G_CALLBACK(chrono_stop), (gpointer)p_gadget);
        g_signal_connect(G_OBJECT(p_gadget->bouton[2]), "clicked", G_CALLBACK(retour_accueil), (gpointer)p_gadget);
        g_signal_connect(G_OBJECT(p_gadget->bouton[3]), "clicked", G_CALLBACK(quitter), (gpointer)p_gadget);
        gtk_widget_show_all(p_gadget->fenetre[0]);
     
    }
     
    void chrono_start(GtkWidget *p_Bouton, gpointer data)
    {
        GADGET *p_gadget=NULL;
        p_gadget=(GADGET*)data;
        p_gadget->chrono=TRUE; //valeur revoyée dans calcul-temps
        p_gadget->temps=time(NULL);
        p_gadget->test=g_timeout_add(1000,calcul_temps,p_gadget);
    }
     
    void chrono_stop(GtkWidget *p_Bouton, gpointer data)
    {
        GADGET *p_gadget=NULL;
        p_gadget=(GADGET*)data;
     
        p_gadget->chrono=FALSE; //valeur revoyée dans calcul-temps
    }
     
    void retour_accueil(GtkWidget *p_Bouton, gpointer data)
    {
        GADGET *p_gadget=NULL;
        p_gadget=(GADGET*)data;
        g_source_remove(p_gadget->test); //arrêter le chrono
        accueil(p_gadget); //retour au double choix du début
    }
     
    void quitter(GtkWidget *p_Bouton, gpointer data)
    {
        GADGET *p_gadget=NULL;
        p_gadget=(GADGET*)data;
     
        g_source_remove(p_gadget->test); //arrêter le chrono
        gtk_main_quit();
    }
     
    gboolean  calcul_temps (gpointer data)
    {
        gchar buf[32];
        GADGET *p_gadget=NULL;
        p_gadget=(GADGET*)data;
        time_t tA=0;
        int tps=0,jour=0,heure=0,min=0;
     
        if (p_gadget->chrono==FALSE)
        {
        return p_gadget->chrono;
        }
     
         tA=time(NULL);
     
         //définir les textes des trois GtkEntry pour  les heures et les minutes les secondes
         tps=tA-p_gadget->temps;
         jour =tps/(24*60*60);
         tps-= jour*24*60*60;
         heure= tps/(60*60);
         tps-=heure*60*60;
         min =tps/60;
         tps-=min*60;
     
         sprintf(buf,"%d",heure);
         gtk_entry_set_text(GTK_ENTRY(p_gadget->entree[0]),buf);
         sprintf(buf,"%d",min);
         gtk_entry_set_text(GTK_ENTRY(p_gadget->entree[1]),buf);
         sprintf(buf,"%d",tps);
         gtk_entry_set_text(GTK_ENTRY(p_gadget->entree[2]),buf);
         gtk_widget_show_all(p_gadget->fenetre[0]);
     
     return p_gadget->chrono;
    }
     
    //callback du bouton décompte --> GtkENtry et boutons
    void decompte(GtkWidget *p_Bouton, gpointer data)
    {
        GADGET *p_gadget=NULL;
        p_gadget=(GADGET*)data;
        GtkWidget *label;
     
        gtk_widget_destroy(p_gadget->VBox[0]);
        p_gadget->VBox[0]=gtk_vbox_new(TRUE,0);
        gtk_container_add (GTK_CONTAINER(p_gadget->fenetre[0]),p_gadget->VBox[0]);
     
        label=gtk_label_new("Entrer le temps du compte à rebour\n h/m/s :");
        gtk_box_pack_start(GTK_BOX(p_gadget->VBox[0]),label,FALSE,FALSE,0);
     
        //les GtkEntry
        p_gadget->entree[0]=gtk_entry_new();
        gtk_entry_set_width_chars(GTK_ENTRY(p_gadget->entree[0]),3);
        p_gadget->entree[1]=gtk_entry_new();
        gtk_entry_set_width_chars(GTK_ENTRY(p_gadget->entree[1]),3);
        p_gadget->entree[2]=gtk_entry_new();
        gtk_entry_set_width_chars(GTK_ENTRY(p_gadget->entree[2]),3);
     
        p_gadget->HBox[0]=gtk_hbox_new(FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->VBox[0]),p_gadget->HBox[0],FALSE,FALSE,0);
     
        label=gtk_label_new("              ");
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[0]),label,FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[0]),p_gadget->entree[0],FALSE,FALSE,0);
        label=gtk_label_new(":");
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[0]),label,FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[0]),p_gadget->entree[1],FALSE,FALSE,0);
        label=gtk_label_new(":");
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[0]),label,FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[0]),p_gadget->entree[2],FALSE,FALSE,0);
     
        p_gadget->HBox[1]=gtk_hbox_new(TRUE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->VBox[0]),p_gadget->HBox[1],FALSE,FALSE,0);
     
        //les boutons
        p_gadget->bouton[0]=  gtk_button_new_with_label("Lancer") ;
        p_gadget->bouton[1]=   gtk_button_new_with_label("Stop") ;
        p_gadget->bouton[2]=   gtk_button_new_with_label("Accueil") ;
        p_gadget->bouton[3]=   gtk_button_new_with_label("Quitter") ;
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[1]),p_gadget->bouton[0],FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[1]),p_gadget->bouton[1],FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[1]),p_gadget->bouton[2],FALSE,FALSE,0);
        gtk_box_pack_start(GTK_BOX(p_gadget->HBox[1]),p_gadget->bouton[3],FALSE,FALSE,0);
     
        g_signal_connect(G_OBJECT(p_gadget->bouton[0]), "clicked", G_CALLBACK(decompte_start), (gpointer)p_gadget);
        g_signal_connect(G_OBJECT(p_gadget->bouton[1]), "clicked", G_CALLBACK(chrono_stop), (gpointer)p_gadget);
        g_signal_connect(G_OBJECT(p_gadget->bouton[2]), "clicked", G_CALLBACK(retour_accueil), (gpointer)p_gadget);
        g_signal_connect(G_OBJECT(p_gadget->bouton[3]), "clicked", G_CALLBACK(quitter), (gpointer)p_gadget);
     
        gtk_widget_show_all(p_gadget->fenetre[0]);
     
    }
     
    void decompte_start(GtkWidget *p_Bouton, gpointer data)
    {
        GADGET *p_gadget=NULL;
        p_gadget=(GADGET*)data;
        const gchar* buf=NULL;
     
        //Entrer le texte du temps à décompter dans les GtkEntry
        p_gadget->chrono=TRUE;
        buf= gtk_entry_get_text(GTK_ENTRY(p_gadget->entree[0]));
        p_gadget->temps=strtol(buf,NULL,10)*60*60;
        buf= gtk_entry_get_text(GTK_ENTRY(p_gadget->entree[1]));
        p_gadget->temps+=strtol(buf,NULL,10)*60;
        buf= gtk_entry_get_text(GTK_ENTRY(p_gadget->entree[2]));
        p_gadget->temps+=strtol(buf,NULL,10);
     
        p_gadget->test=g_timeout_add(1000,calcul_decompte,p_gadget);
     
    }
     
    gboolean  calcul_decompte (gpointer data)
    {
        gchar buf[32];
        GADGET *p_gadget=NULL;
        p_gadget=(GADGET*)data;
        int tps=0,jour=0,heure=0,min=0;
     
        if (p_gadget->chrono==FALSE)
        {
        return p_gadget->chrono;
        }
         p_gadget->temps--;
     
     
         //texte des GtkEntry pendant le décompte
         tps=p_gadget->temps;
         jour =tps/(24*60*60);
         tps-= jour*24*60*60;
         heure= tps/(60*60);
         tps-=heure*60*60;
         min =tps/60;
         tps-=min*60;
     
         sprintf(buf,"%d",heure);
         gtk_entry_set_text(GTK_ENTRY(p_gadget->entree[0]),buf);
         sprintf(buf,"%d",min);
         gtk_entry_set_text(GTK_ENTRY(p_gadget->entree[1]),buf);
         sprintf(buf,"%d",tps);
         gtk_entry_set_text(GTK_ENTRY(p_gadget->entree[2]),buf);
         gtk_widget_show_all(p_gadget->fenetre[0]);
     
        return p_gadget->chrono;
    }

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    172
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 172
    Par défaut
    pour jouer des sons, essayes avec fmod. C'est très puissant et simple d'utilisation

  3. #3
    Membre confirmé Avatar de acryline
    Profil pro
    Inscrit en
    Août 2006
    Messages
    200
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 200
    Par défaut
    Merci pour ta réponse

    Mais n'y a t-il pas plus simple ? Je n'ai pas vraiment envie d'ajouter une autre bibliothèque et apprendre à l'utiliser pour faire un vulgaire "pouet" ou un "tsoin tsoin" quelconque.
    En revanche j'aimerais mettre autre chose que :
    J'ai toujours mon problème de mémoire aussi... (dans mon programme )

  4. #4
    Rédacteur

    Avatar de gege2061
    Femme Profil pro
    Administrateur de base de données
    Inscrit en
    Juin 2004
    Messages
    5 840
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur de base de données

    Informations forums :
    Inscription : Juin 2004
    Messages : 5 840

  5. #5
    Membre confirmé Avatar de acryline
    Profil pro
    Inscrit en
    Août 2006
    Messages
    200
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 200
    Par défaut
    J'aurais aimé pouvoir envoyer un autre son qu'un bip.

    Et j'ai toujours mon p'tit problème de mémoire ...

  6. #6
    Membre Expert
    Homme Profil pro
    Inscrit en
    Janvier 2005
    Messages
    1 259
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 1 259
    Par défaut
    Pour ton problème de mémoire, as-tu tenté de lancer ton programme avec valgrind pour voir si ça te donne une piste ?

  7. #7
    Rédacteur

    Avatar de gege2061
    Femme Profil pro
    Administrateur de base de données
    Inscrit en
    Juin 2004
    Messages
    5 840
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur de base de données

    Informations forums :
    Inscription : Juin 2004
    Messages : 5 840
    Par défaut
    Citation Envoyé par acryline Voir le message
    J'aurais aimé pouvoir envoyer un autre son qu'un bip.
    Dans ce cas il faut passer par une autre bibliothèque pour lire un fichier audio. Regarde du côté de fmod, je crois qu'elle est spécialisée dans ce domaine

  8. #8
    Membre confirmé Avatar de acryline
    Profil pro
    Inscrit en
    Août 2006
    Messages
    200
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 200
    Par défaut
    ok merci Gege2061.. je crois que je vais me contenter de mon petit bip pour l'instant.
    Pour la mémoire j'ai testé le programme avec gdb.. c'est ça ?
    Rapelle de la structure :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    typedef struct GADGET GADGET;
     struct GADGET
     {
       GtkWidget * fenetre[1];
       GtkWidget * VBox[1];
       GtkWidget * HBox[2];
       GtkWidget * bouton[4];
       GtkWidget * entree[3];
       time_t temps;
       gboolean chrono; //valeur retournée dans la fct° périodique
       guint test; //numéro du processus
     };
    si par exemple je mets GtkWidget * entree[4]; à la place de GtkWidget * entree[3] j'obtiens : (avec 3 tout va bien)
    (gdb) run
    Starting program: /home/acryline/programmation/ChronoGTK/bin/Debug/ChronoGTK
    [Thread debugging using libthread_db enabled]
    [New Thread 0xb748c720 (LWP 6200)]

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 0xb748c720 (LWP 6200)]
    0xb7e7b0b3 in gtk_widget_destroy () from /usr/lib/libgtk-x11-2.0.so.0
    (gdb)

  9. #9
    Membre Expert
    Homme Profil pro
    Inscrit en
    Janvier 2005
    Messages
    1 259
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 1 259
    Par défaut
    si quand j'écris valgrind, tu lis gdb, va voir un opticien au plus vite ! :-p

  10. #10
    Membre confirmé Avatar de acryline
    Profil pro
    Inscrit en
    Août 2006
    Messages
    200
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 200
    Par défaut
    rhoooooooo
    Je croyais que c'étais pareil... je connais pas valgrind
    Bon je me renseigne

    Edité : ça m'a l'air bien compliqué. Je n'arrive pas à le faire fonctionner.
    Une petite aide serait la bienvenue

  11. #11
    Membre confirmé Avatar de acryline
    Profil pro
    Inscrit en
    Août 2006
    Messages
    200
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 200
    Par défaut
    J'ai peut être mal cherché mais je n'ai pas trouvé d'explication claire pour installer fmod dans codeblocks sous Linux Debian .. je crois y être arrivée après qq essaies voilà comment je m'y suis prise pour ceux qui cherchent : (Je n'ai pas encore appris à utiliser cette bibliothèque donc je n'ai pas encore pu voir si mon installation est vraiment correcte. En tout cas quand je compile le mini programme je n'ai aucune erreur).

    1. Déjà il faut télécharger la bibliothèque fmod 3 (et pas ex) ici

    2. Vous décompactez le fichier téléchargé où vous voulez (je vais l'appeler "chemin")

    3. Vous créez un dossier FMOD dans /usr/include/ ainsi :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    # mkdir /usr/include/FMOD
    4. Vous y copiez les 4 header du dossier /api/inc/ que vous avez téléchargé :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    #cp /chemin/api/inc/fmoddyn.h /usr/include/FMOD/fmoddyn.h
    #cp /chemin/api/inc/fmod_errors.h /usr/include/FMOD/fmod_errors.h
    #cp /chemin/api/inc/fmod.h /usr/include/FMOD/fmod.h
    #cp /chemin/api/inc/wincompat.h /usr/include/FMOD/wincompat.h
    5. Vous renommez le fichier libfmod-3.75.so du dossier "api" en libfmod.so pour qu'il soit reconnu puis vous le copiez dans le dossier /usr/lib/

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    #cp /chemin/libfmod.so  /usr/lib/libfmod.so
    6. Dans codeblocks ouvrir un nouveau projet console que vous pouvez appeler fmod

    7. Inclure fmod avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    #include <FMOD/fmod.h>
    8. Dans les options de compilations du projet ( Project/build options/ compiler settings/Other options/) mettre : -lfmod

    9. Vérifier si tout se passe bien en compilant le projet. Vous pouvez utiliser ce fichier main.c
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <FMOD/fmod.h>
     
    int main()
    {
        FSOUND_Init(44100, 32, 0);
     
        FSOUND_Close();
        return 0;
    }
    J'obtiens :
    Checking for existence: /home/pseudo/programmation/FMOD/bin/Debug/fmod
    Executing: xterm -T fmod -e /usr/bin/cb_console_runner /home/pseudo/programmation/FMOD/bin/Debug/fmod (in /home/pseudo/programmation/FMOD/.)
    Process terminated with status 0 (0 minutes, 2 seconds)
    10. Enregistrer le projet en tant que template utilisateur (Save project as user-template ) pour pouvoir ouvrir des projets FMOD rapidement.

    Les compléments d'information sont les bienvenus. Merci

  12. #12
    Membre Expert
    Homme Profil pro
    Inscrit en
    Janvier 2005
    Messages
    1 259
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 1 259
    Par défaut
    Citation Envoyé par acryline Voir le message
    Edité : [valgrind] m'a l'air bien compliqué. Je n'arrive pas à le faire fonctionner.
    Une petite aide serait la bienvenue
    il suffit de faire "valgrind ./monprogramme" et d'attendre et ensuite d'analyser le résultat, c'est pas trop compliqué à lancer normalement, c'est l'analyse du résultat qui peut être plus complexe

  13. #13
    Membre confirmé Avatar de acryline
    Profil pro
    Inscrit en
    Août 2006
    Messages
    200
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 200
    Par défaut
    J'ai installé valgrind, et ensuite j'ai tapé valgrind monprogramme dans le dessier du programme. J'obtiens :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    valgrind: ChronoGTK: command not found
    Alors je suis allée faire un tour dans google pour trouver des tuto... c'est pour ça que je trouvais ça compliqué.
    J'ai veriéfié j'ai bien valgrind dans /usr/bin/ pourtant

  14. #14
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 308
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 308
    Billets dans le blog
    5
    Par défaut
    Valgrind va te donner un tas d'information lors du fonctionnement de ton programme. La lecture de ces informations n'est pas très simple mais tout de même faisable.

    La ligne de commande est la suivante pour une utilisation classique :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    valgrind --leak-check=full ./monprogramme
    Tu dois être dans le répertoire de monprogramme et il doit y avoir l'option "-g" lors de la compilation.

  15. #15
    Membre confirmé Avatar de acryline
    Profil pro
    Inscrit en
    Août 2006
    Messages
    200
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 200
    Par défaut
    Merci ! Je viens d'essayer et ça marche. Voici le résultat, effectivement je n'y comprends pas grand chose ...

    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
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
     
    ==6183== Memcheck, a memory error detector.
    ==6183== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
    ==6183== Using LibVEX rev 1804, a library for dynamic binary translation.
    ==6183== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
    ==6183== Using valgrind-3.3.0-Debian, a dynamic binary instrumentation framework
    .
    ==6183== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
    ==6183== For more details, rerun with: -v
    ==6183==
    ==6183== Syscall param write(buf) points to uninitialised byte(s)
    ==6183==    at 0x40007F2: (within /lib/ld-2.7.so)
    ==6183==    by 0x496329E: _X11TransWrite (in /usr/lib/libX11.so.6.2.0)
    ==6183==    by 0x4968BD5: (within /usr/lib/libX11.so.6.2.0)
    ==6183==    by 0x4968CAA: _XReply (in /usr/lib/libX11.so.6.2.0)
    ==6183==    by 0x494EF70: XInternAtom (in /usr/lib/libX11.so.6.2.0)
    ==6183==    by 0x4404DC6: gdk_x11_atom_to_xatom_for_display (in /usr/lib/libgdk-
    x11-2.0.so.0.1200.9)
    ==6183==    by 0x440EFAF: (within /usr/lib/libgdk-x11-2.0.so.0.1200.9)
    ==6183==    by 0x4411A8A: gdk_window_new (in /usr/lib/libgdk-x11-2.0.so.0.1200.9
    )
    ==6183==    by 0x43EE06C: gdk_display_open (in /usr/lib/libgdk-x11-2.0.so.0.1200
    .9)
    ==6183==    by 0x43CB9FC: gdk_display_open_default_libgtk_only (in /usr/lib/libg
    dk-x11-2.0.so.0.1200.9)
    ==6183==    by 0x418824E: gtk_init_check (in /usr/lib/libgtk-x11-2.0.so.0.1200.9
    )
    ==6183==    by 0x4188283: gtk_init (in /usr/lib/libgtk-x11-2.0.so.0.1200.9)
    ==6183==  Address 0x4c18c2c is 340 bytes inside a block of size 16,384 alloc'd
    ==6183==    at 0x4023BDE: calloc (vg_replace_malloc.c:397)
    ==6183==    by 0x4953CBD: XOpenDisplay (in /usr/lib/libX11.so.6.2.0)
    ==6183==    by 0x43EDF11: gdk_display_open (in /usr/lib/libgdk-x11-2.0.so.0.1200
    .9)
    ==6183==    by 0x43CB9FC: gdk_display_open_default_libgtk_only (in /usr/lib/libg
    dk-x11-2.0.so.0.1200.9)
    ==6183==    by 0x418824E: gtk_init_check (in /usr/lib/libgtk-x11-2.0.so.0.1200.9
    )
    ==6183==    by 0x4188283: gtk_init (in /usr/lib/libgtk-x11-2.0.so.0.1200.9)
    ==6183==    by 0x804A4B2: main (main.c:14)
    ==6183==
    ==6183== Invalid read of size 4
    ==6183==    at 0x40170D3: (within /lib/ld-2.7.so)
    ==6183==    by 0x40060F4: (within /lib/ld-2.7.so)
    ==6183==    by 0x4008737: (within /lib/ld-2.7.so)
    ==6183==    by 0x4012A77: (within /lib/ld-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x401233D: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9CC1: (within /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9E84: __libc_dlopen_mode (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x48C3BA6: __nss_lookup_function (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x48C3CBF: (within /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x48C5A95: __nss_passwd_lookup (in /lib/i686/cmov/libc-2.7.so)
    ==6183==  Address 0x4c77fc8 is 32 bytes inside a block of size 34 alloc'd
    ==6183==    at 0x4024AB8: malloc (vg_replace_malloc.c:207)
    ==6183==    by 0x4008D29: (within /lib/ld-2.7.so)
    ==6183==    by 0x4012A77: (within /lib/ld-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x401233D: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9CC1: (within /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9E84: __libc_dlopen_mode (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x48C3BA6: __nss_lookup_function (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x48C3CBF: (within /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x48C5A95: __nss_passwd_lookup (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x4870A02: getpwnam_r (in /lib/i686/cmov/libc-2.7.so)
    ==6183==
    ==6183== Invalid read of size 4
    ==6183==    at 0x4017100: (within /lib/ld-2.7.so)
    ==6183==    by 0x40060F4: (within /lib/ld-2.7.so)
    ==6183==    by 0x4008737: (within /lib/ld-2.7.so)
    ==6183==    by 0x400CA86: (within /lib/ld-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x400D035: (within /lib/ld-2.7.so)
    ==6183==    by 0x4012AD7: (within /lib/ld-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x401233D: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9CC1: (within /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9E84: __libc_dlopen_mode (in /lib/i686/cmov/libc-2.7.so)
    ==6183==  Address 0x4c78310 is 24 bytes inside a block of size 27 alloc'd
    ==6183==    at 0x4024AB8: malloc (vg_replace_malloc.c:207)
    ==6183==    by 0x4008D29: (within /lib/ld-2.7.so)
    ==6183==    by 0x400CA86: (within /lib/ld-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x400D035: (within /lib/ld-2.7.so)
    ==6183==    by 0x4012AD7: (within /lib/ld-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x401233D: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9CC1: (within /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9E84: __libc_dlopen_mode (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x48C3BA6: __nss_lookup_function (in /lib/i686/cmov/libc-2.7.so)
    ==6183==
    ==6183== Invalid read of size 4
    ==6183==    at 0x4017117: (within /lib/ld-2.7.so)
    ==6183==    by 0x40060F4: (within /lib/ld-2.7.so)
    ==6183==    by 0x4008737: (within /lib/ld-2.7.so)
    ==6183==    by 0x4012A77: (within /lib/ld-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x401233D: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9CC1: (within /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9E84: __libc_dlopen_mode (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x48C3BA6: __nss_lookup_function (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x5146FFB: (within /lib/i686/cmov/libnss_compat-2.7.so)
    ==6183==    by 0x51485D4: _nss_compat_getpwnam_r (in /lib/i686/cmov/libnss_compa
    t-2.7.so)
    ==6183==  Address 0x4c789bc is 28 bytes inside a block of size 31 alloc'd
    ==6183==    at 0x4024AB8: malloc (vg_replace_malloc.c:207)
    ==6183==    by 0x4008D29: (within /lib/ld-2.7.so)
    ==6183==    by 0x4012A77: (within /lib/ld-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x401233D: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9CC1: (within /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9E84: __libc_dlopen_mode (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x48C3BA6: __nss_lookup_function (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x5146FFB: (within /lib/i686/cmov/libnss_compat-2.7.so)
    ==6183==    by 0x51485D4: _nss_compat_getpwnam_r (in /lib/i686/cmov/libnss_compa
    t-2.7.so)
    ==6183==    by 0x4870985: getpwnam_r (in /lib/i686/cmov/libc-2.7.so)
    ==6183==
    ==6183== Invalid read of size 4
    ==6183==    at 0x40170D3: (within /lib/ld-2.7.so)
    ==6183==    by 0x40060F4: (within /lib/ld-2.7.so)
    ==6183==    by 0x4008737: (within /lib/ld-2.7.so)
    ==6183==    by 0x400CA86: (within /lib/ld-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x400D035: (within /lib/ld-2.7.so)
    ==6183==    by 0x4012AD7: (within /lib/ld-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x401233D: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9CC1: (within /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9E84: __libc_dlopen_mode (in /lib/i686/cmov/libc-2.7.so)
    ==6183==  Address 0x4c78d00 is 32 bytes inside a block of size 33 alloc'd
    ==6183==    at 0x4024AB8: malloc (vg_replace_malloc.c:207)
    ==6183==    by 0x4008D29: (within /lib/ld-2.7.so)
    ==6183==    by 0x400CA86: (within /lib/ld-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x400D035: (within /lib/ld-2.7.so)
    ==6183==    by 0x4012AD7: (within /lib/ld-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x401233D: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9CC1: (within /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x400E8C5: (within /lib/ld-2.7.so)
    ==6183==    by 0x48E9E84: __libc_dlopen_mode (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x48C3BA6: __nss_lookup_function (in /lib/i686/cmov/libc-2.7.so)
    ==6183==
    ==6183== Conditional jump or move depends on uninitialised value(s)
    ==6183==    at 0x8048EF3: accueil (fonctions.c:24)
    ==6183==    by 0x804A4D7: main (main.c:19)
    ==6183==
    ==6183== Conditional jump or move depends on uninitialised value(s)
    ==6183==    at 0x42B40B1: gtk_widget_destroy (in /usr/lib/libgtk-x11-2.0.so.0.12
    00.9)
    ==6183==    by 0x8048F02: accueil (fonctions.c:26)
    ==6183==    by 0x804A4D7: main (main.c:19)
    ==6183==
    ==6183== Use of uninitialised value of size 4
    ==6183==    at 0x42B40B3: gtk_widget_destroy (in /usr/lib/libgtk-x11-2.0.so.0.12
    00.9)
    ==6183==    by 0x8048F02: accueil (fonctions.c:26)
    ==6183==    by 0x804A4D7: main (main.c:19)
    ==6183==
    ==6183== Invalid read of size 4
    ==6183==    at 0x42B40B3: gtk_widget_destroy (in /usr/lib/libgtk-x11-2.0.so.0.12
    00.9)
    ==6183==    by 0x8048F02: accueil (fonctions.c:26)
    ==6183==    by 0x804A4D7: main (main.c:19)
    ==6183==  Address 0x1000 is not stack'd, malloc'd or (recently) free'd
    ==6183==
    ==6183== Process terminating with default action of signal 11 (SIGSEGV)
    ==6183==  Access not within mapped region at address 0x1000
    ==6183==    at 0x42B40B3: gtk_widget_destroy (in /usr/lib/libgtk-x11-2.0.so.0.12
    00.9)
    ==6183==    by 0x8048F02: accueil (fonctions.c:26)
    ==6183==    by 0x804A4D7: main (main.c:19)
    ==6183==
    ==6183== ERROR SUMMARY: 9 errors from 9 contexts (suppressed: 93 from 1)
    ==6183== malloc/free: in use at exit: 183,457 bytes in 2,705 blocks.
    ==6183== malloc/free: 5,445 allocs, 2,740 frees, 497,261 bytes allocated.
    ==6183== For counts of detected errors, rerun with: -v
    ==6183== searching for pointers to 2,705 not-freed blocks.
    ==6183== checked 755,272 bytes.
    ==6183==
    ==6183==
    ==6183== 156 (36 direct, 120 indirect) bytes in 1 blocks are definitely lost in
    loss record 50 of 94
    ==6183==    at 0x4024AB8: malloc (vg_replace_malloc.c:207)
    ==6183==    by 0x48C3E02: (within /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x48C464D: __nss_database_lookup (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x5146FDB: ???
    ==6183==    by 0x51485D4: ???
    ==6183==    by 0x4870985: getpwnam_r (in /lib/i686/cmov/libc-2.7.so)
    ==6183==    by 0x45DC727: (within /usr/lib/libglib-2.0.so.0.1600.1)
    ==6183==    by 0x45DE043: g_get_home_dir (in /usr/lib/libglib-2.0.so.0.1600.1)
    ==6183==    by 0x41D7A1D: (within /usr/lib/libgtk-x11-2.0.so.0.1200.9)
    ==6183==    by 0x41D7D68: gtk_rc_reparse_all_for_settings (in /usr/lib/libgtk-x1
    1-2.0.so.0.1200.9)
    ==6183==    by 0x41F3553: gtk_settings_get_for_screen (in /usr/lib/libgtk-x11-2.
    0.so.0.1200.9)
    ==6183==    by 0x41F36E4: gtk_settings_get_default (in /usr/lib/libgtk-x11-2.0.s
    o.0.1200.9)
    ==6183==
    ==6183==
    ==6183== 800 bytes in 20 blocks are possibly lost in loss record 73 of 94
    ==6183==    at 0x4023BDE: calloc (vg_replace_malloc.c:397)
    ==6183==    by 0x45B2504: g_malloc0 (in /usr/lib/libglib-2.0.so.0.1600.1)
    ==6183==    by 0x4550E94: (within /usr/lib/libgobject-2.0.so.0.1600.1)
    ==6183==    by 0x4551034: (within /usr/lib/libgobject-2.0.so.0.1600.1)
    ==6183==    by 0x4554D8C: g_type_register_fundamental (in /usr/lib/libgobject-2.
    0.so.0.1600.1)
    ==6183==    by 0x455FA44: (within /usr/lib/libgobject-2.0.so.0.1600.1)
    ==6183==    by 0x4553DD7: g_type_init_with_debug_flags (in /usr/lib/libgobject-2
    .0.so.0.1600.1)
    ==6183==    by 0x4553EC1: g_type_init (in /usr/lib/libgobject-2.0.so.0.1600.1)
    ==6183==    by 0x43CBB45: gdk_pre_parse_libgtk_only (in /usr/lib/libgdk-x11-2.0.
    so.0.1200.9)
    ==6183==    by 0x4188654: (within /usr/lib/libgtk-x11-2.0.so.0.1200.9)
    ==6183==    by 0x45B83FC: g_option_context_parse (in /usr/lib/libglib-2.0.so.0.1
    600.1)
    ==6183==    by 0x41881CB: gtk_parse_args (in /usr/lib/libgtk-x11-2.0.so.0.1200.9
    )
    ==6183==
    ==6183==
    ==6183== 30,288 bytes in 22 blocks are possibly lost in loss record 93 of 94
    ==6183==    at 0x4023A92: memalign (vg_replace_malloc.c:460)
    ==6183==    by 0x4023B3F: posix_memalign (vg_replace_malloc.c:569)
    ==6183==    by 0x45C6AF3: (within /usr/lib/libglib-2.0.so.0.1600.1)
    ==6183==    by 0x45C7CCB: g_slice_alloc (in /usr/lib/libglib-2.0.so.0.1600.1)
    ==6183==    by 0x45C7E14: g_slice_alloc0 (in /usr/lib/libglib-2.0.so.0.1600.1)
    ==6183==    by 0x4558AA6: g_type_create_instance (in /usr/lib/libgobject-2.0.so.                                                                             0.1600.1)
    ==6183==    by 0x453E1E1: (within /usr/lib/libgobject-2.0.so.0.1600.1)
    ==6183==    by 0x453E9A7: g_object_newv (in /usr/lib/libgobject-2.0.so.0.1600.1)
    ==6183==    by 0x453F4F0: g_object_new_valist (in /usr/lib/libgobject-2.0.so.0.1                                                                             600.1)
    ==6183==    by 0x453F65F: g_object_new (in /usr/lib/libgobject-2.0.so.0.1600.1)
    ==6183==    by 0x43EDF37: gdk_display_open (in /usr/lib/libgdk-x11-2.0.so.0.1200                                                                             .9)
    ==6183==    by 0x43CB9FC: gdk_display_open_default_libgtk_only (in /usr/lib/libg                                                                             dk-x11-2.0.so.0.1200.9)
    ==6183==
    ==6183== LEAK SUMMARY:
    ==6183==    definitely lost: 36 bytes in 1 blocks.
    ==6183==    indirectly lost: 120 bytes in 10 blocks.
    ==6183==      possibly lost: 31,088 bytes in 42 blocks.
    ==6183==    still reachable: 152,213 bytes in 2,652 blocks.
    ==6183==         suppressed: 0 bytes in 0 blocks.
    ==6183== Reachable blocks (those to which a pointer was found) are not shown.
    ==6183== To see them, rerun with: --leak-check=full --show-reachable=yes
    Erreur de segmentation
    J'ai édité pour mettre la citation en code.

  16. #16
    Membre Expert
    Homme Profil pro
    Inscrit en
    Janvier 2005
    Messages
    1 259
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 1 259
    Par défaut
    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
     
    ==6183== Conditional jump or move depends on uninitialised value(s)
    ==6183== at 0x8048EF3: accueil (fonctions.c:24)
    ==6183== by 0x804A4D7: main (main.c:19)
    ==6183==
    ==6183== Conditional jump or move depends on uninitialised value(s)
    ==6183== at 0x42B40B1: gtk_widget_destroy (in /usr/lib/libgtk-x11-2.0.so.0.12
    00.9)
    ==6183== by 0x8048F02: accueil (fonctions.c:26)
    ==6183== by 0x804A4D7: main (main.c:19)
    ==6183==
    ==6183== Use of uninitialised value of size 4
    ==6183== at 0x42B40B3: gtk_widget_destroy (in /usr/lib/libgtk-x11-2.0.so.0.12
    00.9)
    ==6183== by 0x8048F02: accueil (fonctions.c:26)
    ==6183== by 0x804A4D7: main (main.c:19)
    ==6183==
    ==6183== Invalid read of size 4
    ==6183== at 0x42B40B3: gtk_widget_destroy (in /usr/lib/libgtk-x11-2.0.so.0.12
    00.9)
    ==6183== by 0x8048F02: accueil (fonctions.c:26)
    ==6183== by 0x804A4D7: main (main.c:19)
    ==6183== Address 0x1000 is not stack'd, malloc'd or (recently) free'd
    ==6183==
    ==6183== Process terminating with default action of signal 11 (SIGSEGV)
    ==6183== Access not within mapped region at address 0x1000
    ==6183== at 0x42B40B3: gtk_widget_destroy (in /usr/lib/libgtk-x11-2.0.so.0.12
    00.9)
    ==6183== by 0x8048F02: accueil (fonctions.c:26)
    ==6183== by 0x804A4D7: main (main.c:19)
    La partie intéressante se trouve ci-dessus, valgrind commence par te dire qu'à la ligne 24 de fonctions.c, tu fais un test sur une valeur qui n'a jamais été initialisée, idem pour le GtkWidget que tu passes en argument à gtk_widget_destroy à la ligne 26. Le crash semble découler de l'utilisation de cette zone mémoire que tu n'as jamais initialisée

  17. #17
    Membre confirmé Avatar de acryline
    Profil pro
    Inscrit en
    Août 2006
    Messages
    200
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 200
    Par défaut
    Merci ! C'est magique.
    La fonction concernée dans fonctions.c est :
    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
     
    //choix chrono ou décompte
    void accueil(GADGET *p_gadget)
    {
      if (p_gadget->VBox[0]) // ligne 24
      {
          gtk_widget_destroy(p_gadget->VBox[0]);  //ligne 26
      }
      p_gadget->VBox[0]=gtk_vbox_new(TRUE,0);
      gtk_container_add (GTK_CONTAINER(p_gadget->fenetre[0]),p_gadget->VBox[0]);
      p_gadget->bouton[0]=  gtk_button_new_with_label("Chronomètre") ;
      p_gadget->bouton[1]=  gtk_button_new_with_label("Décompte") ;
      gtk_box_pack_start(GTK_BOX(p_gadget->VBox[0]),p_gadget->bouton[0],TRUE,TRUE,0);
      gtk_box_pack_start(GTK_BOX(p_gadget->VBox[0]),p_gadget->bouton[1],TRUE,TRUE,0);
      gtk_widget_show_all(p_gadget->fenetre[0]);
     
      g_signal_connect(G_OBJECT(p_gadget->bouton[0]), "clicked", G_CALLBACK(chrono), (gpointer)p_gadget);
      g_signal_connect(G_OBJECT(p_gadget->bouton[1]), "clicked", G_CALLBACK(decompte), (gpointer)p_gadget);
      g_signal_connect(G_OBJECT(p_gadget->fenetre[0]), "destroy", G_CALLBACK(quitter), NULL);
     
    }
    Quand le programme commence rien a été affiché dans la fenêtre et je détruis la boîte gadget.Vbox [0].
    Je pensais que ce test allait éviter le problème, et bien non... suis je bête, on ne peux pas voir si une valeur non initialisée existe !!
    Il m'a suffit d'initialiser la boîte avant d'appeler la fonction et le problème a été réglé.
    En tout cas m erci à tout le monde.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème sur Structure Incluant un GTK image
    Par diophantes dans le forum GTK+ avec C & C++
    Réponses: 5
    Dernier message: 02/06/2007, 00h03
  2. Réponses: 16
    Dernier message: 21/08/2006, 14h12
  3. [Structures]Problème sur structures
    Par kendras dans le forum C++
    Réponses: 5
    Dernier message: 07/06/2006, 10h20
  4. Réponses: 2
    Dernier message: 05/06/2006, 13h39
  5. [OCaml] Problème de structure/parser
    Par marv1 dans le forum Caml
    Réponses: 4
    Dernier message: 09/05/2005, 12h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo