This line of code results in the error Segmentation Fault (Core dumped):

collision = detectCollision(window, ball);

if (strcmp(getType(collision), "GRect") == 0)
    // TODO           

What is causing the segfault and how can I fix it?

2 Answers 2


You may also have to make sure it's not null before you try to pass it into getType(). detectCollision will return null when there are no collisions.

  • That did it for me - just adding the check to make sure object is not NULL ended the core dumps for me. Thanks!
    – user2742
    Oct 13, 2014 at 14:04
  • thanks dude, it was exactly this for me, not checking f it was NULL at first... Sep 27, 2015 at 16:27

What type have you initialized the variable "collision" to be? If you initialized it as a string, that could be the issue.

Make sure you are initializing it as:

GObject collision = detectCollision(window, ball);

You must log in to answer this question.

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