Projet C++ Doom-like segmentation fault

Fermé
alakasta Messages postés 1 Date d'inscription lundi 21 décembre 2009 Statut Membre Dernière intervention 21 décembre 2009 - 21 déc. 2009 à 11:26
Bonjour,

Je travail sur un doom-like et lors de l'execution j'ai une erreur du type :
10 [main] game 80344 _cygtls::handle_exceptions: Error while dumping state
(probably corrupted stack)
Segmentation fault (core dumped)

Je suis sur Vista Pro SP1 et travail avec cygwin 1.5.25-15 entièrement installé.
Le hic s'est que sur linux pas d'erreur d'execution...


Voilà déjà mon main si quelqu'un peut m'aider ?

/**
* \file main.cpp
* \brief Game Doom-like.
* \author Serge Metrailler et Martin Page
* \version 1.0
* \date 25.11.07
*
* Jeu video conçu en 3D isometrique.
*
*/
//#include "includes.h"
//#include <vector>
//#include "bmpfile.h"
#include "perso.h"

/**
* \fn int main ()
* \brief Entrée du programme.
*
* \return EXIT_SUCCESS - Arrêt normal du programme.
*/
int main()
{
Niveau n;
n.chargeNiveau();
Personnage h(V2(30,30),V2(15,15));
Personnage m(V2(160,50),V2(21.2132,0));

Drawable d;
Display *display;
int ww = 500, wh = 500;
Window window, windowmap;
GC gc;


//! Connection au serveur X
const char *serverName = getenv("DISPLAY");
display = XOpenDisplay(serverName ? serverName : ":0.0");
if(display == NULL)
{
fprintf(stderr, "Cannot connect to X server\n");
}

//! Recuperation de l'ecran principal
int screen = DefaultScreen(display);

//! Creation d'une fenetre
window = XCreateSimpleWindow
(display, RootWindow(display, screen),0, 0, ww, wh, 0, 0, 0xffffff);
windowmap = XCreateSimpleWindow
(display, RootWindow(display, screen),0, 0, ww, wh, 0, 0, 0xffffff);
//! Selectionne les evenements qui nous interessent
//! Ici on ne prend que les touches clavier
XSelectInput(display, window, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask);

//! Affiche la fenetre
XMapWindow(display, window);
XMapWindow(display, windowmap);

//! Obtient un contexte d'affichage
gc = XCreateGC(display, window, 0, NULL);

Pixmap pixmap = XCreatePixmap(display, window, ww, wh, 24);
Pixmap pixmap1 = XCreatePixmap(display, window, ww, wh, 24);

//! Cree l'image (le XImage)
unsigned int *px = new unsigned int[ww * wh];
XImage *img = XCreateImage(
display, //! Connection
DefaultVisual(display, screen), //! Visuel
24, //! Profondeur
ZPixmap, //! Type
0, //! Offset du debut de ligne
(char*)px, //! Donnees
ww, wh, //! Dimensions
8, //! Padding en bits (8,16 ou 32)
ww * 4); //! Taille d'une scanline

//! Ordre des octets
img->byte_order = LSBFirst;

char *key = new char[2];
bool running = true;
KeySym sym;

h.a = false;
h.b = false;
h.c = false;
h.d = false;

while(running)
{
XSetForeground(display, gc, 0xffffff);
XFillRectangle(display, pixmap, gc, 0, 0, ww, wh);
XFillRectangle(display, pixmap1, gc, 0, 0, ww, wh);

//! Gestion des evenements (boucle active)
XEvent evt;
while(XPending(display))
{
//! Recoit l'evenement.
XNextEvent(display, &evt);
switch(evt.type)
{

case KeyPress:
XLookupString((XKeyPressedEvent *) &evt, key, 1, &sym, NULL);

switch(sym)
{

//! Quitte quand on presse q.
case 113:
running = 0;
break;

//! Avance quand on presse UP ARROW
case 119:
h.a = true;

break;

//! Recule quand on presse DOWN ARROW
case 115:
h.b = true;

break;

//! Tourne a droite quand on presse RIGHT ARROW
case 100:

h.c = true;

break;

//! Tourne a gauche quand on presse LEFT ARROW
case 97:
h.d = true;

break;
}

break;

case KeyRelease:
XLookupString((XKeyReleasedEvent *) &evt, key, 1, &sym, NULL);

switch(sym)
{

//! Relachement de UP ARROW
case 119:
h.a = false;
break;

//! Relachement de DOWN ARROW
case 115:
h.b = false;
break;

//! Relachement de RIGHT ARROW
case 100:
h.c = false;
break;

//! Relachement de LEFT ARROW
case 97:
h.d = false;
break;
}

break;
}

//! Deplacements
if(h.a == true)
{
h.pos = h.pos + h.dir/20;
}
if(h.b ==true)
{
h.pos = h.pos - h.dir/20;
}
if(h.c == true)
{
h.dir = V2(h.dir.x*cos(2*3.1415/360)-h.dir.y*sin(2*3.1415/360),
h.dir.x*sin(2*3.1415/360)+h.dir.y*cos(2*3.1415/360));
h.dirUni = h.dir/h.dir.norme();
}
if(h.d == true)
{
h.dir = V2( h.dir.x*cos(-2*3.1415/360)-h.dir.y*sin(-2*3.1415/360),
h.dir.x*sin(-2*3.1415/360)+h.dir.y*cos(-2*3.1415/360));
h.dirUni = h.dir/h.dir.norme();
}
}

//! Appel des fonctions d'affichage et de proximite

//! Monstre
m.proximiteMur(n.listeMur1);
m.proximitePersonnage(h);

XSetForeground(display, gc, 0x000000);

//! Petite sale apres deuxieme teleportation
if(h.teleportation)
{
for(int i=0; i<n.listeMur2.size(); ++i)
{
n.listeMur2[i].afficheMur(display,pixmap1,gc);
}
h.affiche3D(n.listeMur2, n.listeObjet, display, pixmap, gc, ww, wh);
h.proximiteMur(n.listeMur2);
}

//! Map principale
else
{
for(int i=0; i<n.listeMur1.size(); ++i)
{
n.listeMur1[i].afficheMur(display,pixmap1,gc);
}
h.affiche3D(n.listeMur1, n.listeObjet, display, pixmap, gc, ww, wh);
h.proximiteMur(n.listeMur1);
}

//! Humain et monstre sur la carte
XSetForeground(display, gc, 0x000000);

XDrawLine(display, pixmap1 , gc, (int)h.pos.x, (int)h.pos.y, (int)h.pos.x+(int)h.dir.x, (int)h.pos.y+(int)h.dir.y);

if(!h.teleportation)
{
XDrawLine(display, pixmap1, gc, (int)m.pos.x, (int)m.pos.y, (int)m.pos.x+(int)m.dir.x, (int)m.pos.y+(int)m.dir.y);
}

//! Pixmap
XCopyArea(display, pixmap, window, gc, 0, 0, ww, wh, 0, 0);
XCopyArea(display, pixmap1, windowmap, gc, 0, 0, ww, wh, 0, 0);
XFlush(display);

usleep(100000);
}

//! Libere le contexte d'affichage
XFreeGC(display, gc);

//! Detruit la fenetre
XUnmapWindow(display, window);
XDestroyWindow(display, window);

//! Deconnection du serveur X
XCloseDisplay(display);

return EXIT_SUCCESS;
}