Skip to content

Commit 13d43bb

Browse files
committed
Fix tag clear hang
1 parent 60e9296 commit 13d43bb

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Clearing an entity with inherited tags no longer hangs.
13+
1014
## [5.2.2] - 2024-08-03
1115

1216
### Fixed

tcod/ecs/entity.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,12 @@ def remove(self, tag: object) -> None:
650650
raise KeyError(tag)
651651
self.discard(tag)
652652

653+
def clear(self) -> None:
654+
"""Remove all tags directly in this entity."""
655+
_tags_by_entity = self.entity.registry._tags_by_entity
656+
while _tags_by_entity[self.entity]:
657+
self.discard(next(iter(_tags_by_entity[self.entity])))
658+
653659
def __contains__(self, x: object) -> bool:
654660
"""Return True if this entity has the given tag."""
655661
_tags_by_entity = self.entity.registry._tags_by_entity

tests/test_traversal.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,13 @@ def test_relation_traversal() -> None:
205205
assert len(world["C"].relation_components[str]) == 2 # noqa: PLR2004
206206
world["C"].relation_components[int][world["foo"]] = 0
207207
assert set(world["C"].relation_components) == {str, int}
208+
209+
210+
def test_inherited_clear() -> None:
211+
world = Registry()
212+
world["A"].components[int] = 1
213+
world["A"].tags.add("foo")
214+
world["A"].relation_components[str][world["B"]] = "bar"
215+
world["A"].relation_tags["baz"] = world["B"]
216+
child = world["A"].instantiate()
217+
child.clear() # Could hang if broken

0 commit comments

Comments
 (0)