1

code

This is my code. My particular problem is in the else if where I am checking if a brick has been returned. For some reason when I execute remove(window, object), it doesn't remove the instance of the brick and it just stays there. The points get updated though, as well as the scoreboard and the direction. As I am checking if the object is NULL at the beginning of the code (can't be seen in the screenshot), there should be an existing object that I am giving the remove function. Also the window object is legit, as it does update the scoreboard. What can be causing this behavior?

1

You should use removeGWindow not remove. Per the specs

SPL’s documentation incorrectly refers to that function as remove, but it’s indeed removeGWindow you want, whose prototype, to be clear, is the below.

void removeGWindow(GWindow gw, GObject gobj);
  • Thanks a lot. Somehow I failed to see it mentioned in the exercise. Now everything is working! :) – TsvetaB Apr 2 '15 at 18:18
  • when I use the same code it gives me Segmentation fault... it's only solved when I add object != NULL That is : else if(object!=NULL && strcmp(getType(object), "GRect") == 0) { removeGWindow(window, object); } – user7612 Jul 25 '15 at 7:12
  • @MahmoudSherifHabib I'm not sure whether you have a question or are trying to add an answer. – Kareem Jul 25 '15 at 7:15
  • @Kareem I want to know why I get Segmentation fault if I don't add object != NULL – user7612 Jul 26 '15 at 14:00
  • @MahmoudSherifHabib because getType tries to access/read data that belongs to theGObject that is passed to it as an argument. reading from NULL causes segfault. – Kareem Jul 27 '15 at 11:38

You must log in to answer this question.

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