From b1161791479625b484c0f76934664d9050360ce1 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 31 Dec 2020 16:28:28 +0000 Subject: Fix: prevent crash with MAX_ENTITIES are used The look would crash if all the entities are used, so we count how many entities we process in the loop. --- game/src/game.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/game/src/game.c b/game/src/game.c index bc52b2a..6a85ad2 100644 --- a/game/src/game.c +++ b/game/src/game.c @@ -370,6 +370,8 @@ void update_player() void run_game() { + uint8_t i; + // init some variables; look at game.h for description lives = MAX_LIVES; invuln = 0; @@ -421,7 +423,7 @@ void run_game() // - self is a pointer to THIS entity // - because we don't create/destroy entities dynamically // when we found one that is unused we are done - for (self = entities; self->type; self++) + for (i = 0, self = entities; i < MAX_ENTITIES && self->type; i++, self++) self->update(); // ensure we wait to our desired update rate -- cgit v1.2.3