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. Commented Jun 24, 2014 at 22:39

2 Answers 2

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
    Commented Jun 25, 2014 at 5:59
  • @Loic you may vote up the answer and accept it if it was useful!
    – kzidane
    Commented Jun 25, 2014 at 8:13
  • This answers helped me, too.
    – Chin Hung
    Commented Sep 12, 2015 at 15:56
  • had the same problem. thank you !
    – Angelos
    Commented Nov 6, 2015 at 13:00
  • Also helped me, I was returning GRect instead of paddle in my initPaddle() function.
    – Tremyr
    Commented Nov 8, 2015 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
    Commented Jun 24, 2014 at 18:02

You must log in to answer this question.

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