2

I am trying to get the paddle moving with the mouse but I keep getting the same error message : "Segmentation Fault (Core Dumped)".

This is my function, which is very simple. Any suggestions?

// keep playing until game over
while (lives > 0 && bricks > 0)
{

    // follow mouse forever
    while (true)
    {
        // check for mouse event
        GEvent event = getNextEvent(MOUSE_EVENT);

        // if we heard one
        if (event != NULL)
        {
            // if the event was movementc
            if (getEventType(event) == MOUSE_MOVED)
            {
                // ensure paddle follows top cursor
                double x = getX(event);
                double y = 500;
                setLocation(paddle, x, y);
            }
        }
    }
}
1
  • I think the problem isn't there. Try to run with gdb, see what is the last line before the error. – Mateus Pires Jun 24 '14 at 22:39
5

You get a segmentation fault when you touch locations in memory that you shouldn't! Make sure your initPaddle() function doesn't return NULL and returns the paddle you created within it instead!

5
  • That was absolutely it. Thank you. – Loic Jun 25 '14 at 5:59
  • @Loic you may vote up the answer and accept it if it was useful! – Kareem Jun 25 '14 at 8:13
  • This answers helped me, too. – Chin Hung Sep 12 '15 at 15:56
  • had the same problem. thank you ! – Angelos Nov 6 '15 at 13:00
  • Also helped me, I was returning GRect instead of paddle in my initPaddle() function. – Tremyr Nov 8 '15 at 0:55
1

Take out that while(true) loop. It's enough with the while (lives > 0 && bricks > 0)

1
  • Thanks. I tried. I still get the same "Segmentation Fault"... – Loic Jun 24 '14 at 18:02

You must log in to answer this question.

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