Copy the entities set into a list before iterating it so there's no risk of modifying the array while iterating

This commit is contained in:
Eryn Wells 2022-05-08 23:43:08 -07:00
parent cef1ad25cb
commit 7d871e52a9

View file

@ -9,6 +9,7 @@ import tcod
from .actions import Action, ActionResult, ExitAction, RegenerateRoomsAction, BumpAction, WaitAction
from .geometry import Direction
from .object import Actor
if TYPE_CHECKING:
from .engine import Engine
@ -40,7 +41,12 @@ class EventHandler(tcod.event.EventDispatch[Action]):
if not result.success and result.done:
return
for ent in self.engine.entities:
# Copy the list so we only act on the entities that exist at the start of this turn
entities = list(self.engine.entities)
for ent in entities:
if not isinstance(ent, Actor):
continue
ent_ai = ent.ai
if not ent_ai:
continue