2

I am trying to detect collisions between the ball and paddle or bricks. The difficulty for me is trying to determine if detectCollision is returning NULL. An excerpt from my code is shown below.

This code seems to be causing the error "Segmentation fault (core dumped)." Is it my first IF statement that is causing the problem?

      // Detects a collision between the ball and another object
      if (detectCollision() != NULL)
      {
          GObject collision = detectCollision(window, ball);
          if (strcmp(getType(collision), "GRect") == 0)
          {
               velocity_y = -velocity_y;
          }
      }
3

I was having a similar problem when I moved from:

if (object == paddle)

to:

if (strcmp(getType(object), "GRect") == 0)

After reading your question, I realized I was probably not handling NULL correctly, and so I went back and did a check to make sure the object being returned by getCollision was not equal to NULL. Then, things worked better. In your code, I would try doing:

GObject collision = detectCollision(window, ball);
if (collision != NULL)
{
   // check object type, etc.
}

You must log in to answer this question.

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