1

I instatiated the bricks and paddle without any trouble, but when I try to have the paddle move with the mouse I get a segmentation fault. And this error doesn't occur until I move my mouse over the new window.

while (lives > 0 && bricks > 0)
    {

    GEvent event = getNextEvent(MOUSE_EVENT);

    if (event != NULL)
    {
        if(getEventType(event) == MOUSE_MOVED)
        {
            double x = getX(event) - PWT / 2;
            double y = PY;
            setLocation(paddle, x, y);  
        }
    }
}

I saw similar cases where people left NULL as the return for initPaddle, but I changed that return as below. Why do I get a segmentation fault? Am I putting in th wrong return, or did instatiating the bricks first somehow interfere?

GRect initPaddle(GWindow window)
{
GRect paddle = newGRect((getWidth(window) - PWT)/2 , PY, PWT, PHT);
setColor(paddle, "BLACK");
setFilled(paddle, true);
add(window, paddle);
return newGRect;
}

1 Answer 1

1

GRect initPaddle(GWindow window) your returning a newGRect, does that even compile. You should return the paddle from the line with GRect paddle = newGRect((getWidth(window) - PWT)/2 , PY, PWT, PHT);

You must log in to answer this question.

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