Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1130 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  origine de l'erreur incomprise Bus Error (lib GLUT OpenGL)

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

origine de l'erreur incomprise Bus Error (lib GLUT OpenGL)

n°2118697
blacktanke​r
Posté le 29-12-2011 à 15:36:53  profilanswer
 

Bonjour, si je viens quérir de l'aide ici c'est que je n'ai pas réussi malgré mes recherches à comprendre mon erreur.
Je programme un tetris avec la librairie GLUT de OpenGL. Le problème survient lorsque que je désire déplacer la pièce vers la gauche. Ceci viens de la manière de détecter la collision du bords gauche. Mais je ne trouve pas mon erreur.
voici mon code:

Code :
  1. #include <stdlib.h> /*Utilisé pour la fonction "exit"*/
  2. #include <math.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdarg.h>
  6. #include <time.h>
  7. #ifdef __APPLE__
  8. #include <OpenGL/OpenGL.h>
  9. #include <GLUT/glut.h>
  10. #else
  11. #include <GL/glut.h>
  12. #endif
  13. #define X_MIN 100  // Les positions du cadre
  14. #define X_MAX 350
  15. #define Y_MIN 050
  16. #define Y_MAX 550
  17. /*fonction update timer*/
  18. /*fonction décrémente*/
  19. /******************************************---Variables********************************************************************************************/    
  20. int pieces[7][4][4][4]={
  21.      {//L
  22.       {//p1
  23.        {0,0,0,0},
  24.        {0,1,1,0},
  25.        {0,1,0,0},
  26.        {0,1,0,0}
  27.       },
  28.       {//p2
  29.        {0,0,0,0},
  30.        {0,1,1,1},
  31.        {0,0,0,1},
  32.        {0,0,0,0}
  33.       },
  34.       {//p3
  35.        {0,0,0,0},
  36.        {0,0,1,0},
  37.        {0,0,1,0},
  38.        {0,1,1,0}
  39.       },
  40.       {//p4
  41.        {0,0,0,0},
  42.        {0,1,0,0},
  43.        {0,1,1,1},
  44.        {0,0,0,0}
  45.       }
  46.      },
  47.      {//L2
  48.       {//p1
  49.        {0,0,0,0},
  50.        {0,1,1,0},
  51.        {0,0,1,0},
  52.        {0,0,1,0}
  53.       },
  54.       {//p2
  55.        {0,0,0,0},
  56.        {0,0,0,1},
  57.        {0,1,1,1},
  58.        {0,0,0,0}
  59.       },
  60.       {//p3
  61.        {0,0,0,0},
  62.        {0,1,0,0},
  63.        {0,1,0,0},
  64.        {0,1,1,0}
  65.       },
  66.       {//4
  67.        {0,0,0,0},
  68.        {0,1,1,1},
  69.        {0,1,0,0},
  70.        {0,0,0,0}
  71.       }
  72.      },
  73.      {//barre
  74.       {//bh
  75.        {0,0,0,0},
  76.        {1,1,1,1},
  77.        {0,0,0,0},
  78.        {0,0,0,0}
  79.       },
  80.       {//bv
  81.        {0,1,0,0},
  82.        {0,1,0,0},
  83.        {0,1,0,0},
  84.        {0,1,0,0}
  85.       },
  86.       {//bh
  87.        {0,0,0,0},
  88.        {1,1,1,1},
  89.        {0,0,0,0},
  90.        {0,0,0,0}
  91.       },
  92.       {//bv
  93.        {0,1,0,0},
  94.        {0,1,0,0},
  95.        {0,1,0,0},
  96.        {0,1,0,0}
  97.       }
  98.      },
  99.      {//carre
  100.       {//p1
  101.        {0,0,0,0},
  102.        {0,1,1,0},
  103.        {0,1,1,0},
  104.        {0,0,0,0}
  105.       },
  106.       {//p2
  107.        {0,0,0,0},
  108.        {0,1,1,0},
  109.        {0,1,1,0},
  110.        {0,0,0,0}
  111.       },
  112.       {//p3
  113.        {0,0,0,0},
  114.        {0,1,1,0},
  115.        {0,1,1,0},
  116.        {0,0,0,0}
  117.       },
  118.       {//p4
  119.        {0,0,0,0},
  120.        {0,1,1,0},
  121.        {0,1,1,0},
  122.        {0,0,0,0}
  123.       }
  124.      },
  125.      {//T
  126.       {//p1
  127.        {0,0,0,0},
  128.        {0,1,1,1},
  129.        {0,0,1,0},
  130.        {0,0,0,0}
  131.       },
  132.       {//p2
  133.        {0,0,0,0},
  134.        {0,1,0,0},
  135.        {0,1,1,0},
  136.        {0,1,0,0}
  137.       },
  138.       {//p3
  139.        {0,0,0,0},
  140.        {0,0,1,0},
  141.        {0,1,1,1},
  142.        {0,0,0,0}
  143.       },
  144.       {//p4
  145.        {0,0,0,0},
  146.        {0,0,1,0},
  147.        {0,1,1,0},
  148.        {0,0,1,0}
  149.       }
  150.      },
  151.      {//S
  152.       {//p1
  153.        {0,0,0,0},
  154.        {0,1,1,0},
  155.        {0,0,1,1},
  156.        {0,0,0,0}
  157.       },
  158.       {//p2
  159.        {0,0,0,0},
  160.        {0,0,1,0},
  161.        {0,1,1,0},
  162.        {0,1,0,0}
  163.       },
  164.       {//p3
  165.        {0,0,0,0},
  166.        {0,1,1,0},
  167.        {0,0,1,1},
  168.        {0,0,0,0}
  169.       },
  170.       {//p4
  171.        {0,0,0,0},
  172.        {0,0,1,0},
  173.        {0,1,1,0},
  174.        {0,1,0,0}
  175.       }
  176.      },
  177.      {//Z
  178.       {//p1
  179.        {0,0,0,0},
  180.        {0,0,1,1},
  181.        {0,1,1,0},
  182.        {0,0,0,0}
  183.       },
  184.       {//p2
  185.        {0,0,0,0},
  186.        {0,1,0,0},
  187.        {0,1,1,0},
  188.        {0,0,1,0}
  189.       },
  190.       {//p3
  191.        {0,0,0,0},
  192.        {0,0,1,1},
  193.        {0,1,1,0},
  194.        {0,0,0,0}
  195.       },
  196.       {//p4
  197.        {0,0,0,0},
  198.        {0,1,0,0},
  199.        {0,1,1,0},
  200.        {0,0,1,0}
  201.       }
  202.      }
  203.     };
  204. int terrain[22][12]={{0,0,0,0,0,0,0,0,0,0,0,0},
  205.      {0,0,0,0,0,0,0,0,0,0,0,0},
  206.      {0,0,0,0,0,0,0,0,0,0,0,0},
  207.      {0,0,0,0,0,0,0,0,0,0,0,0},
  208.      {0,0,0,0,0,0,0,0,0,0,0,0},
  209.      {0,0,0,0,0,0,0,0,0,0,0,0},
  210.      {0,0,0,0,0,0,0,0,0,0,0,0},
  211.      {0,0,0,0,0,0,0,0,0,0,0,0},
  212.      {0,0,0,0,0,0,0,0,0,0,0,0},
  213.      {0,0,0,0,0,0,0,0,0,0,0,0},
  214.      {0,0,0,0,0,0,0,0,0,0,0,0},
  215.      {0,0,0,0,0,0,0,0,0,0,0,0},
  216.      {0,0,0,0,0,0,0,0,0,0,0,0},
  217.      {0,0,0,0,0,0,0,0,0,0,0,0},
  218.      {0,0,0,0,0,0,0,0,0,0,0,0},
  219.      {0,0,0,0,0,0,0,0,0,0,0,0},
  220.      {0,0,0,0,0,0,0,0,0,0,0,0},
  221.      {0,0,0,0,0,0,0,0,0,0,0,0},
  222.      {0,0,0,0,0,0,0,0,0,0,0,0},
  223.      {0,0,0,0,0,0,0,0,0,0,0,0},
  224.      {0,0,0,0,0,0,0,0,0,0,0,0},
  225.      {0,0,0,0,0,0,0,0,0,0,0,0}};
  226. int terrainfix[22][12]={{1,1,1,1,1,1,1,1,1,1,1,1},
  227.      {1,0,0,0,0,0,0,0,0,0,0,1},
  228.      {1,0,0,0,0,0,0,0,0,0,0,1},
  229.      {1,0,0,0,0,0,0,0,0,0,0,1},
  230.      {1,0,0,0,0,0,0,0,0,0,0,1},
  231.      {1,0,0,0,0,0,0,0,0,0,0,1},
  232.      {1,0,0,0,0,0,0,0,0,0,0,1},
  233.      {1,0,0,0,0,0,0,0,0,0,0,1},
  234.      {1,0,0,0,0,0,0,0,0,0,0,1},
  235.      {1,0,0,0,0,0,0,0,0,0,0,1},
  236.      {1,0,0,0,0,0,0,0,0,0,0,1},
  237.      {1,0,0,0,0,0,0,0,0,0,0,1},
  238.      {1,0,0,0,0,0,0,0,0,0,0,1},
  239.      {1,0,0,0,0,0,0,0,0,0,0,1},
  240.      {1,0,0,0,0,0,0,0,0,0,0,1},
  241.      {1,0,0,0,0,0,0,0,0,0,0,1},
  242.      {1,0,0,0,0,0,0,0,0,0,0,1},
  243.      {1,0,0,0,0,0,0,0,0,0,0,1},
  244.      {1,0,0,0,0,0,0,0,0,0,0,1},
  245.      {1,0,0,0,0,0,0,0,0,0,0,1},
  246.      {1,0,0,0,0,0,0,0,0,0,0,1},
  247.      {1,1,1,1,1,1,1,1,1,1,1,1}};
  248. int piece_choisie[4][4]={{0}};
  249. int score=0;
  250. int x,y;
  251. int i;int d=1;
  252. int my=450, mx=100;
  253. int choix; int orientation=0 ;
  254. /***choix*/
  255. void determination()
  256.    {
  257. srand(time(NULL));
  258.     choix= rand()%6;
  259. printf (" choix = %d \n", choix);
  260. }
  261. /******************************************---Base/Carre---****************************************************************************************/
  262. void base(int x,int y) // creation de la base qui servira pour toutes les figures (ensemble de carre) float r,float v,float b
  263. {
  264. // float colr = (rand()%255)/255.0;
  265. // float colv = (rand()%255)/255.0;
  266. // float colb = (rand()%255)/255.0;
  267. int colr=0;
  268. int colv=1;
  269. int colb=1;
  270. glBegin(GL_POLYGON);
  271.     glColor3f(colr,colv,colb);
  272.     glVertex2f(x*25,y*25);
  273.     glColor3f(colr,colv,0);
  274.     glVertex2f(25+x*25,y*25);
  275.     glColor3f(colr,colv,colb);
  276.     glVertex2f(25+x*25,25+y*25);
  277.     glColor3f(1,1,1);
  278.     glVertex2f(x*25,25+y*25);
  279.     glEnd();
  280.     glFlush();
  281. glutSwapBuffers() ;
  282. }
  283. /************************/
  284. int Collision(int terrain[22][12],int terrainfix[22][12],int piece_choisie[4][4],int my,int mx)
  285. int i,j;
  286. for(i=0;i<4;i++)
  287. {
  288.  for(j=0;j<4;j++)
  289.  {
  290.   if(piece_choisie[i][j]==1 && terrainfix[i+my][j+mx]==1) // permet de garder les contours lorsque la piece les approches
  291.   {
  292.   return 1;
  293.   }
  294.   if(piece_choisie[i][j]==1 && terrain[i+my][j+mx]==1) // permet de garder les contours lorsque la piece les approches
  295.   {
  296.   return 1;
  297.   }
  298.  }
  299. }
  300. return 0;
  301. }
  302. /******************************************---Chute---**********************************************************************************************/
  303. int Chute(int y, int x)
  304. {
  305. if(my>0)
  306. {
  307.   my=my-1;
  308.   printf (" chute my = %d \n", my);
  309.   printf (" chute mx = %d \n", mx);
  310.   glutPostRedisplay();
  311. }
  312. else
  313. {
  314. my=my;
  315. printf (" chute my = %d \n", my);
  316. printf (" chute mx = %d \n", mx);
  317. int i,j;
  318. for(i=0;i<4;i++)
  319.         {
  320.             for(j=0;j<4;j++)
  321.             {
  322.   terrain[i+my][j+mx]=terrain[i+my][j+mx]+piece_choisie[i][j];
  323.   }
  324.         }
  325. for( x=0;x<12;x++)
  326. {
  327.  for(y=0;y<22;y++)
  328.  {
  329.   printf (" terrain[%d][%d] = %d \n", y, x, terrain[y][x]);
  330.  }
  331. }
  332. }
  333. return 0;
  334. }
  335. /******************************************---Dessine les pieces---********************************************************************************/
  336. void dessin_piece(int pieces[7][4][4][4])
  337. {
  338.   
  339. for( x=0;x<4;x++)
  340. {
  341.      for(y=0;y<4;y++)
  342.      {
  343.   piece_choisie[y][x]=pieces[choix][orientation][y][x];
  344.   printf (" piece[%d][%d][%d][%d] = %d \n", choix, orientation, y, x, pieces[choix][orientation][y][x]);
  345.          if(piece_choisie[y][x]==1)
  346.          {
  347.              base(x,y);
  348.          }
  349.     }
  350. }
  351. }
  352. /******************************************---Dessine le terrain---********************************************************************************/
  353. void dessin_terrainfix(int terrainfix[22][12])
  354. {
  355.     
  356. for( x=0;x<12;x++)
  357. {
  358.      for(y=0;y<22;y++)
  359.      {
  360.          if(terrainfix[y][x]==1)
  361.          {
  362.              base(x,y);
  363.          }
  364.     }
  365. }
  366. }
  367. void dessin_terrain(int terrain[22][12])
  368. {
  369.     
  370. for( x=0;x<12;x++)
  371. {
  372.      for(y=0;y<22;y++)
  373.      {
  374.          if(terrain[y][x]==1)
  375.          {
  376.              base(x,y);
  377.          }
  378.     }
  379. }
  380. }
  381. /******************************************---Fonction pour utiliser du texte---*******************************************************************/
  382. void bitmap_output(int x,int y,char *string,void *font) {
  383.   int len,i;
  384.   glRasterPos2f(x,y);
  385.   len = (int) strlen(string);
  386.   for (i = 0; i < len; i++) {
  387.     glutBitmapCharacter(font,string[i]); }
  388. }
  389. /******************************************---Fenetre---*******************************************************************************************/
  390. void dessin(void) //fonction de dessin
  391. {
  392.     glClear(GL_COLOR_BUFFER_BIT);
  393. glLoadIdentity();
  394. glColor3f(1, 0, 0);
  395. bitmap_output(470,350,"Score:",GLUT_BITMAP_HELVETICA_18);
  396. glTranslatef(100,25,0);
  397. dessin_terrainfix(terrainfix);
  398. dessin_terrain(terrain);
  399. printf (" dessin mx = %d \n ", mx);
  400. glTranslatef(mx,my,0);
  401. Chute(my,mx);
  402. dessin_piece(pieces);
  403. }
  404. /******************************************---Restructuration de la fenetre et changement de repere---*********************************************/
  405. void reshape(int w, int h)
  406. {
  407. glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  408. glMatrixMode(GL_PROJECTION);
  409. glLoadIdentity();
  410. glOrtho(0, 600, 0, 600, -1, 1);
  411. glMatrixMode(GL_MODELVIEW);
  412. glLoadIdentity();
  413. }
  414. /******************************************---Fonctions de Déplacements---*************************************************************************/
  415. void deplacement_gauche()
  416. {
  417. if(Collision(terrain,terrainfix,piece_choisie,my,mx-1)==0)
  418. {
  419. mx=mx-5;
  420. printf (" key mx = %d \n", mx);
  421. glutPostRedisplay();
  422. }
  423. else
  424. {
  425. mx=mx;
  426. }
  427. }
  428. /******************************************---Touches Special du Clavier---*************************************************************************/
  429. void GestionSpecial(int key, int x, int y)
  430. {
  431. switch (key)
  432.   {
  433.   case GLUT_KEY_RIGHT:
  434.  
  435.  if(mx<200)
  436.     {mx=mx+5;
  437.  printf (" key mx = %d \n", mx);
  438.  glutPostRedisplay();
  439.  break;}
  440.  else
  441.  {mx=mx;
  442.  break;}
  443.   case GLUT_KEY_LEFT:
  444.  deplacement_gauche();break;
  445.   case GLUT_KEY_UP:
  446.  
  447.  if(my<450)
  448.     {my=my+1;
  449.  printf (" key my = %d \n", my);
  450.  glutPostRedisplay();
  451.  break;}
  452.  else
  453.  {my=my;
  454.  break;}
  455.   case GLUT_KEY_DOWN:
  456.  
  457.  if(my>0)
  458.     {my=my-5;
  459.  printf (" key my = %d \n", my);
  460.  glutPostRedisplay();
  461.  break;}
  462.  else
  463.  {my=my;
  464.  break;}
  465.   case GLUT_KEY_F1 :
  466.  glutPostRedisplay() ;
  467.  break;
  468.   }
  469. }
  470. /******************************************---Touches du Clavier---*********************************************************************************/
  471. void keyboard(unsigned char key, int x, int y)
  472. {
  473.   switch (key)
  474.   {
  475.   case ' ':
  476.   if(orientation!=3)
  477.    {
  478. orientation=orientation+1 ;
  479.     glutPostRedisplay();
  480. break;
  481.    }
  482.    else
  483.    {
  484.    orientation=0;
  485.    glutPostRedisplay();
  486.    break;}
  487.  
  488.  
  489.   case 99 /*c*/:
  490.     if(choix!=6)
  491.    {
  492. choix=choix+1 ;
  493.     glutPostRedisplay() ;
  494. break;
  495.    }
  496.    else
  497.    {
  498.    choix=0;
  499.    glutPostRedisplay();
  500.    break;}
  501.  
  502.    case 120/*x*/:
  503.  
  504.     printf (" dessin \n" );
  505. srand(time(NULL));
  506.     choix= rand()%6;
  507. glutPostRedisplay() ;
  508. break;
  509.   case 27 /* Esc */:
  510.     exit(1) ;
  511.   }
  512. }
  513. /******************************************---Fonction Principal---*********************************************************************************/
  514. int main(int argc, char **argv)
  515. {
  516.  
  517.   glutInit(&argc, argv) ;
  518.   glutInitWindowSize(600,600);
  519.   glutInitWindowPosition(300,150);
  520.   glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE) ;
  521.   glutCreateWindow("Tetris" ) ;
  522.   determination();
  523.   glutDisplayFunc(dessin) ;
  524.   glutReshapeFunc(reshape);
  525.   //glutMotionFunc(motion) ;
  526.   glutKeyboardFunc(keyboard) ;
  527.   glutSpecialFunc(GestionSpecial);
  528.   glutMainLoop() ;
  529.   return 0 ;
  530. }


 
J'espère que vous pourrez m'aider.
Merci.

mood
Publicité
Posté le 29-12-2011 à 15:36:53  profilanswer
 

n°2118699
blacktanke​r
Posté le 29-12-2011 à 15:38:30  profilanswer
 

Je précise que la compilation se fait sans problème mais le Bus Error survient à l'exécution.

n°2118714
Joel F
Real men use unique_ptr
Posté le 29-12-2011 à 16:51:00  profilanswer
 

c'ets du C, mauvaise cat.
Ensuite, gdb est ton ami.

n°2118738
blacktanke​r
Posté le 29-12-2011 à 18:46:54  profilanswer
 

je suis sous mac. oui je sais c'est bizarre de faire du C sur mac. Mais c la consigne.

n°2118754
Joel F
Real men use unique_ptr
Posté le 30-12-2011 à 07:48:44  profilanswer
 

et ? y a gdb sous mac aussi, et je te parlais que la categorie du forum etait incorrect.

n°2118800
theshockwa​ve
I work at a firm named Koslow
Posté le 30-12-2011 à 15:28:56  profilanswer
 

les bus error, ca peut pas être du à des accès mal alignés ? T'es sur du mac PowerPC ou x86 ?


---------------
last.fm

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  origine de l'erreur incomprise Bus Error (lib GLUT OpenGL)

 

Sujets relatifs
erreur de compilationErreur d'écriture de fichier RMAN ORA-27040 Oracle
probleme execution animation openglcolorer surface bezier opengl C++
pb Webservice erreur NullPointerException [résolu]Erreur de script PHP pour crontab
[C#] erreur dans le codeerreur d'exécution script
c++ opengl charger image texture 
Plus de sujets relatifs à : origine de l'erreur incomprise Bus Error (lib GLUT OpenGL)


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR