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 Answer
You should use removeGWindow
not remove
. Per the specs
SPL’s documentation incorrectly refers to that function as
remove
, but it’s indeedremoveGWindow
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! :)– TsvetaBApr 2, 2015 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); }
– user7612Jul 25, 2015 at 7:12 -
@MahmoudSherifHabib I'm not sure whether you have a question or are trying to add an answer.– kzidane ♦Jul 25, 2015 at 7:15
-
@Kareem I want to know why I get Segmentation fault if I don't add
object != NULL
– user7612Jul 26, 2015 at 14:00 -
@MahmoudSherifHabib because
getType
tries to access/read data that belongs to theGObject
that is passed to it as an argument. reading fromNULL
causes segfault.– kzidane ♦Jul 27, 2015 at 11:38