summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/game.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 9d184ea..fedc403 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -146,13 +146,11 @@ void state_t::tick(double now_, double dt_)
u.d = dt;
dice_prng.seed(dice_prng.next() ^ u.i);
- // NOTE: on_think can erase the entity from awake_entities.
- for (auto i = awake_entities.begin(); i != awake_entities.end(); ) {
- auto next = i;
- next++;
- (*i)->on_think();
- i = next;
- }
+ // on_think can insert/erase elements of awake_entities so iterate
+ // over a copy of it.
+ auto copy = awake_entities;
+ for (entity_t *ent : copy)
+ ent->on_think();
}
die_t::die_t(size_t sides_)