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?


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.

| improve this answer | |
  • 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 '14 at 14:04
  • thanks dude, it was exactly this for me, not checking f it was NULL at first... – Vladimir Moreno Romeo Sep 27 '15 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);

| improve this answer | |

You must log in to answer this question.

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