0

After coding my Bricks for BREAKOUT, I get Segmentation error and my Paddle, Ball, and Scoreboard no longer appear! The bricks look great, but everything else disappeared and I get the fault error. Here is my code:

    void initBricks(GWindow window)
    {
       int brick1 = 4;
       int brick2 = 40;
       string colors[5];
       colors[0] = "RED"
       colors[1] = "ORANGE"
       colors[2] = "YELLOW"
       colors[3] = "GREEN"
       colors[4] = "BLUE"

    for(int row = 0; row <= ROWS; row++)
    {
      for(int col = 0; col<= COLS; col++, brick1 += 40) 
      { 
        GRect brick = newGRect(brick1, brick2, WIDTH/13, 10);
        setFilled(brick, true);
        setColor(brick, colors[row]);
        add(window, brick);      
      }
      brick2 += 20;
     brick1 = 4;
    }
   }
9
  • you probably should update your question with the code! – Kareem Jun 22 '15 at 14:41
  • I don't think what's causing the segfault is in that piece of code. – Kareem Jun 22 '15 at 16:21
  • Everything worked fine until I added that code in and now the bricks are the only thing that appear in my window. Before the code I had a ball, a paddle, and the scoreboard. Now when I run the code, only the bricks appear and I haven't changed anything else! I'm at a loss! – Ty Powell Jun 22 '15 at 17:05
  • looking by the eye, I still don't see the cause of the segfault here. why don't you try valgrind? – Kareem Jun 22 '15 at 18:14
  • I can't figure it out. I've coded the rest of the program and I can't implement my bricks so I'm going to have to find a different way to code them I guess. Thanks. – Ty Powell Jun 23 '15 at 6:14
0

Check if brick == NULL before setting any properties. And report so we can see is there any progress :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .