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

C++ Discussion :

gtkmm windows et erreur


Sujet :

C++

  1. #1
    Membre éclairé Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Par défaut gtkmm windows et erreur
    bonjour,

    j'ai installé gtkmm avec codeblocks sous vista et j'ai un problème inattendu :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    This application has requested  the Runtime  to terminate  it in an unusaul way.
    apparaît quand je lance mon programme.

    Avez vous une idée ? Le code fonctionne parfaitement sous linux.

    edit : voici le code de ma fenêtre :

    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
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
     
    //fichier h
    #ifndef INTERFACE_HH
    #define INTERFACE_HH
     
    #include <fstream>
    #include <iostream>
    #include <cstdlib>
    #include <list>
    #include <gtkmm.h>
    #include <cstdlib>
    #include "ZoneJoueur.hh"
    #include "ZoneJeu.hh"
    #include "ImageInfo.hh"
     
    extern "C"
    {
    	#include <time.h>
    }
     
    class Fenetre : public Gtk::Window
    {
    	private:
    		const static std::string TITRE;
    		static std::string fichierImages;
    		static int taillePixbuf;
    		const static int NB_IMAGES;
    		const static std::string icon;
    		const static int NB_LIGNE_PAR_IMAGE;
    		const static int NB_MAX_TIRAGE_ALEA;
     
    		Gtk::VBox vbox;
    		Gtk::HBox hbox;
     
    		int nbJoueur;
    		ZoneJoueur *zoneJoueur;
     
    		ZoneJeu zoneJeu;
     
    		int nbImages;
    		ImageInfo *images;
    		bool *imageDistribuee;
    		int *imageID;
    		int nbImagesDistribuee;
     
    		int jeton; // id du joueur qui peux jouer entre 0 et nbJoueur-1
     
    		bool lectureFichierDeConf();
    		int alea();
     
    	public :
    		const static std::string imageDefault;
     
    		Fenetre();
    		virtual ~Fenetre(void);
     
    		ImageInfo& getImage(int n);
    		ImageInfo& getImageNonUtilisee(bool& succes);
    		ImageInfo& getImageJoueur(int zone, int image);
    		void removeImageJoueur(int zone, int image);
    		static int getTaillePixbuf();
     
    		ZoneJoueur& getZoneJoueur(int zone);
    		int getNbJoueur();
     
    		int getJeton();
    		void incJeton(int id);
     
    		int getNbRestante(); // nombre de cartes restantes
    };
     
    #endif
     
     
     
     
    // fichier cpp
    #include "interface.hh"
     
    using namespace std;
     
    const string Fenetre::TITRE="Titre tmp by Rniamo ;)";
    const string Fenetre::imageDefault="Images/Cases/default.png";
    const string Fenetre::icon="Images/Autres/icon.png";
    const int Fenetre::NB_IMAGES=77;
    const int Fenetre::NB_LIGNE_PAR_IMAGE=10;
    const int Fenetre::NB_MAX_TIRAGE_ALEA=20;
    string Fenetre::fichierImages="images.txt";
    int Fenetre::taillePixbuf=128;
     
    bool Fenetre::lectureFichierDeConf()
    {
    	// récupération des images
    	ifstream fimages(Fenetre::fichierImages.c_str());
    	long debut=fimages.tellg();
    	bool err=false;
    	if (fimages.is_open())
    	{
    		// on compte le nombre de lignes = le nombre d'images
    		string ligne;
    		int nb=0;
    		while(getline(fimages,ligne))
    			nb++;
    		nbImages=nb/Fenetre::NB_LIGNE_PAR_IMAGE;
    		if (nbImages*Fenetre::NB_LIGNE_PAR_IMAGE!=nb || nbImages<5) //NB_IMAGES)
    			return false;
    		fimages.seekg(debut,ios_base::beg);
    		fimages.clear();
     
    		// On alloue
    		if (nbImages>0)
    		{
    			try
    			{
    				images=new ImageInfo[nbImages];
    				imageDistribuee=new bool[nbImages];
    				imageID=new int[nbImages];
    				for (int i=5;i<nbImages;i++)
    				{
    					imageDistribuee[i]=false;
    					imageID[i]=i;
    				}
    				for (int i=0;i<5;i++)
    				{
    					imageID[i]=i;
    					imageDistribuee[i]=true;
    					nbImagesDistribuee++;
    				}
    			}
    			catch(std::bad_alloc&)
    			{
    				cout << "Erreur d'allocation" << endl;
    			}
    		}
    		fimages.close();
    	}
     
    	fimages.open(Fenetre::fichierImages.c_str());
    	if (fimages.is_open())
    	{
    		// On charge les images
    		int i=0, nl=0;
    		string ligne;
    		ImageInfo::cote dr, gche, ht, ba, drd, gched, htd, bad;
    		while(getline(fimages,ligne))
    		{
    			switch( (nl % Fenetre::NB_LIGNE_PAR_IMAGE) )
    			{
    				default:
    					try {
    						images[i].set(Gdk::Pixbuf::create_from_file(ligne,Fenetre::taillePixbuf,Fenetre::taillePixbuf,true));
    					}
    					catch(Gdk::PixbufError&){}
    					catch(Glib::FileError&){cout << "erreur image : " << ligne << endl;}
    				break;
     
    				case 1: 	dr=ImageInfo::int2Cote(atoi(ligne.c_str()));  	images[i].setDroit(dr); 				break;
    				case 2: 	gche=ImageInfo::int2Cote(atoi(ligne.c_str()));	images[i].setGauche(gche); 				break;
    				case 3: 	ht=ImageInfo::int2Cote(atoi(ligne.c_str()));  	images[i].setHaut(ht); 					break;
    				case 4: 	ba=ImageInfo::int2Cote(atoi(ligne.c_str()));  	images[i].setBas(ba); 					break;
     
    				case 5:
    					try {
    						images[i].getImageDessous().set(Gdk::Pixbuf::create_from_file(ligne,Fenetre::taillePixbuf,Fenetre::taillePixbuf,true));
    					}
    					catch(Gdk::PixbufError&){}
    					catch(Glib::FileError&){cout << "erreur image : " << ligne << endl;}
    				break;
     
    				case 6: 	drd=ImageInfo::int2Cote(atoi(ligne.c_str()));  	images[i].setDroitDessous(drd); 			break;
    				case 7: 	gched=ImageInfo::int2Cote(atoi(ligne.c_str())); images[i].setGaucheDessous(gched);			break;
    				case 8: 	htd=ImageInfo::int2Cote(atoi(ligne.c_str()));  	images[i].setHautDessous(htd); 				break;
    				case 9: 	bad=ImageInfo::int2Cote(atoi(ligne.c_str()));  	images[i++].setBasDessous(bad); 			break;
    			}
    			nl++;
    		}
     
    		fimages.close();
    		err=true;
    	}
     
    	return err;
    }
     
    int Fenetre::alea() // entre 5 et nbImages
    {
    	static bool b=false;
    	if (!b)
    	{
    		b=!b;
    		srand(time(NULL));
    	}
    	return static_cast<int>(5+(nbImages-5)*(rand()*1.0/RAND_MAX));
    }
     
    ImageInfo& Fenetre::getImageNonUtilisee(bool& succes)
    {
    	if (nbImagesDistribuee<nbImages)
    	{
    		int i, cpt=0;
    		do
    		{
    			i=alea();
    			cpt++;
    			if (cpt>Fenetre::NB_MAX_TIRAGE_ALEA)
    			{
    				int j=5; // village+ couleurs
    				while(imageDistribuee[j++]);
    				i=j;
    			}
    		}while(imageDistribuee[alea()]);
    		succes=true;
    		imageDistribuee[i]=true;
    		nbImagesDistribuee++;
    		return images[i];
    	}
    	succes=false;
    	return images[0];
    }
     
     
    Fenetre::Fenetre() //:
    //vbox(false,0), hbox(false,0), nbJoueur(4), zoneJeu(this), nbImages(0), images(NULL), imageDistribuee(NULL), imageID(NULL), nbImagesDistribuee(0), jeton(0)
    {
        cout << "constructeur fenetre" << endl;
     
    	/*set_title(Fenetre::TITRE);
    	set_icon_from_file(icon);
    	add(vbox);
     
    	if (nbJoueur<=1)
    		exit(-1);
     
    	if (!lectureFichierDeConf())
    	{
    		Gtk::MessageDialog dialog(*this,"Erreur :\n",false,Gtk::MESSAGE_QUESTION,Gtk::BUTTONS_OK);
    		dialog.set_secondary_text("Probleme avec le fichier 'images'.\nLe programme va quitter.");
    		if (dialog.run()==Gtk::RESPONSE_OK)
    			dialog.hide();
    		exit(-1);
    	}
     
    	try
    	{
    		zoneJoueur=new ZoneJoueur[nbJoueur];
    	}
    	catch(bad_alloc&)
    	{
    		cout << "Erreur allocation des zoneJoueur." << endl;
    	}
     
    	bool t[]={false,false,false,false};//couleurs
     
    	for (int i=0;i<nbJoueur;i++)
    	{
    		zoneJoueur[i].setFenetre(this);
    		int n;
    		do
    		{
    			n=static_cast<int>((alea()-5)*4*(1.0/nbImages));
    		}while(t[n]);
    		t[n]=true;
    		zoneJoueur[i].setCouleur(images[n]);
    	}
     
    	// Joueur 1
    	if (nbJoueur>=1)
    	{
    		vbox.pack_start(zoneJoueur[0],false,false);
    		zoneJoueur[0].setFeuVert();
    	}
     
    	// grille et Joueur 2 et 3
    	vbox.pack_start(hbox);
     
    	if (nbJoueur>=3)
    	{
    		hbox.pack_start(zoneJoueur[2],false,false);
    		zoneJoueur[2].setOrientation(false);
    	}
     
    	hbox.pack_start(zoneJeu);
    	zoneJeu.ajout(images[4],1,1); // village
    	zoneJeu.raffraichir();
     
    	if (nbJoueur>=4)
    	{
    		hbox.pack_start(zoneJoueur[3],false,false);
    		zoneJoueur[3].setOrientation(false);
    	}
     
    	if (nbJoueur>=2)
    		vbox.pack_start(zoneJoueur[1],false,false);
     
    	// dnd
    	list<Gtk::TargetEntry> listTargets;
    	listTargets.push_back(Gtk::TargetEntry("STRING"));
    	listTargets.push_back(Gtk::TargetEntry("text/plain"));
    	for(int i=0;i<nbJoueur;i++)
    		zoneJoueur[i].setSourceDrag();
    	zoneJeu.getTable().drag_dest_set(listTargets);
    */
    	// affichage
    	show_all();
    }
     
    Fenetre::~Fenetre()
    {
    	if (images)
    		delete [] images;
    	if (zoneJoueur)
    		delete [] zoneJoueur;
    	if (imageDistribuee)
    		delete [] imageDistribuee;
    	if (imageID)
    		delete [] imageID;
    }
     
    ImageInfo& Fenetre::getImage(int n)
    {
    	if (n<nbImages)
    		return images[n];
    	return images[0];
    }
     
    ImageInfo& Fenetre::getImageJoueur(int zone, int image)
    {
    	if(zone<nbJoueur && image<zoneJoueur[zone].getNbImage())
    		return zoneJoueur[zone].getImage(image).getImage();
    	return zoneJoueur[0].getImage(0).getImage();
    }
     
    int Fenetre::getTaillePixbuf()
    {
    	return Fenetre::taillePixbuf;
    }
     
    int Fenetre::getJeton()
    {
    	return jeton;
    }
     
    void Fenetre::incJeton(int id)
    {
    	if (id!=jeton)
    		return;
     
    	getZoneJoueur(jeton).setFeuRouge();
    	jeton+=1;
    	jeton%=nbJoueur;
     
    	int i=jeton;
    	while(zoneJoueur[jeton].getNbCarteRestante()<=0)
    	{
    		jeton++;
    		jeton%=nbJoueur;
    		if (jeton==i)
    			return; // partie finie
    	}
    	getZoneJoueur(jeton).setFeuVert();
    }
     
    void Fenetre::removeImageJoueur(int zone, int image)
    {
    	if(zone<nbJoueur && image<zoneJoueur[zone].getNbImage())
    		zoneJoueur[zone].removeImage(image);
    }
     
    int Fenetre::getNbRestante()
    {
    	return (nbImages-nbImagesDistribuee);
    }
     
    ZoneJoueur& Fenetre::getZoneJoueur(int zone)
    {
    	if (zone<nbJoueur)
    		return zoneJoueur[zone];
    	return zoneJoueur[0];
    }
     
    int Fenetre::getNbJoueur()
    {
    	return nbJoueur;
    }

  2. #2
    Membre éclairé Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Par défaut
    j'ai trouvé d'où vient le problème :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    defaultImage(Gdk::Pixbuf::create_from_file(Fenetre::imageDefault,Fenetre::getTaillePixbuf(),Fenetre::getTaillePixbuf(),true))
    En commentant cette partie ma fenêtre se lance mais il n'y a rien dedans (ce qui est bizarre.

    J'ai aussi remarqué en faisant des tests que les images n'étaient pas chargée, un problème dû aux pixbufs ? Problème de librairies ?

    Programme de test, voici mon main :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Gtk::Window fenetre;
    	Glib::RefPtr<Gdk::Pixbuf> pix=Gdk::Pixbuf::create_from_file("Images\\Autres\\icon.png",128,128,true);
    	Gtk::Image im(pix);
    	fenetre.add(im);
    	fenetre.show_all_children();
    J'obtient la même erreur.

    edit : une version des sources est là : http://rniamo.olympe-network.com/Programmation/LGDM.zip

  3. #3
    Expert confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2003
    Messages
    3 549
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 3 549
    Par défaut
    Dans le cas où le fichier n'existe pas, ça lève une exception ou ça fait un objet vide ?

  4. #4
    Membre éclairé Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Par défaut
    ça lève une exception mais les fichiers existent, c'est ça le problème.

    J'ai même essayé :

    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
    Gtk::Main kit(argc, argv);
    	//Fenetre fenetre;
    	Gtk::Window fenetre;
    	Glib::RefPtr<Gdk::Pixbuf> pix;
    	try
    	{
            pix=Gdk::Pixbuf::create_from_file("Images\\Autres\\icon.png",128,128,true);
    	}
    	catch(Glib::FileError &)
    	{
                cout << "erreur de fichier" << endl;
    	}
    	catch(Gdk::PixbufError 	&)
    	{
    	    cout << "erreur de pixbuf" << endl;
        }
    	Gtk::Image im(pix);
    	fenetre.add(im);
    	fenetre.show_all_children();
    	Gtk::Main::run(fenetre);
    et le résultat est le même.

  5. #5
    Membre éclairé Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Par défaut
    je n'y arrive pas, je vient de constater qu'en gtk+ les pixbuf ne marchaient pas mais je ne sais pas pourquoi.

  6. #6
    Membre éclairé Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Par défaut
    je viens de voir que je n'ai l'erreur qu'en lançant le programme depuis code::blocks. Si je le lance via vista je n'ai pas cette erreur.

  7. #7
    Expert confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2003
    Messages
    3 549
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 3 549
    Par défaut
    T'as essayé d'utiliser un débogueur pour voir ce qui se passe ?

  8. #8
    Membre éclairé Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Par défaut
    j'ai essayé le debugeur mais le problème vient de ma configuration des runtime sous code::blocks (je ne vois pas pourquoi le programme se lancerait sinon).

  9. #9
    Membre éclairé Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Par défaut
    je crois que j'ai trouvé (pas testé sous windows) : j'ai testé sous linux et j'avais un problème similaire => le répertoire de lancement du jeu n'était pas bin/Debug ou bin/Release mais .

  10. #10
    Membre éclairé Avatar de Rniamo
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    508
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 508
    Par défaut
    c'était bien ça, je viens de vérifier.

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

Discussions similaires

  1. Service Windows et erreur 1069
    Par Luc1an0 dans le forum Windows XP
    Réponses: 4
    Dernier message: 20/12/2011, 17h05
  2. [windows Me] Erreurs lors de l'impression
    Par C_C dans le forum Windows 2000/Me/98/95
    Réponses: 2
    Dernier message: 09/07/2007, 23h22
  3. Réponses: 1
    Dernier message: 22/03/2007, 10h21
  4. [windows.h] Erreur du linker : LNK2019
    Par Cube* dans le forum Visual C++
    Réponses: 3
    Dernier message: 01/09/2006, 22h40
  5. bug à la connexion internet sous Windows xp (erreur 0x001405f3)
    Par adrienj dans le forum Dépannage et Assistance
    Réponses: 3
    Dernier message: 11/05/2006, 01h24

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