From 149a1180d1941fd672b7befc5b54fed1f17b3a4c Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Mon, 2 Jan 2023 21:06:09 +0000 Subject: [PATCH] Fixed a bug with the ObjectStore which would have caused some objects to be ignored when running the game-loop functions. --- src/ObjectStore.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ObjectStore.c b/src/ObjectStore.c index e546feb..cf17cdb 100644 --- a/src/ObjectStore.c +++ b/src/ObjectStore.c @@ -93,7 +93,13 @@ void remove_object_from_store(ObjectStore *os, ObjectID *id_ptr) { os->reusable_ids[(os->deleted_count)++] = id; - os->count -= 1; + if (id == (os->count - 1)) { + // Only decrement the count if the last object is deleted. Otherwise, the + // count shouldn't be decremented since the deleted object would be in the + // middle, which means that the functions that loop over all objects in the + // store will not actually loop over everything + os->count -= 1; + } } void handle_all_objects_events(ObjectStore *os, const SDL_Event *event) {