Skip to content

Commit 04f06a1

Browse files
committed
workaround for objects that appear in selections but not in tracker events somehow
1 parent b8982c2 commit 04f06a1

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

sc2reader/engine/plugins/context.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,14 @@ def handleSelectionEvent(self, event, replay):
8585

8686
# If we have tracker events, the unit must already exist and must already
8787
# have the correct unit type.
88+
elif unit_id in replay.objects:
89+
unit = replay.objects[unit_id]
90+
91+
# Except when it doesn't.
8892
else:
89-
unit = replay.objects[unit_id]
93+
unit = replay.datapack.create_unit(unit_id, unit_type, event.frame)
94+
replay.objects[unit_id] = unit
95+
9096

9197
# Selection events hold flags on units (like hallucination)
9298
unit.apply_flags(intra_subgroup_flags)
Binary file not shown.
Binary file not shown.

test_replays/test_all.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ def test_creepTracker(self):
387387
assert replay.player[2].creep_spread_by_minute[420] == 9.4
388388
assert replay.player[2].creep_spread_by_minute[780] == 22.42
389389

390+
def test_bad_unit_ids(self):
391+
replay = sc2reader.load_replay("test_replays/2.0.11.26825/bad_unit_ids_1.SC2Replay", load_level=4)
392+
replay = sc2reader.load_replay("test_replays/2.0.9.26147/bad_unit_ids_2.SC2Replay", load_level=4)
393+
394+
390395

391396
class TestGameEngine(unittest.TestCase):
392397
class TestEvent(object):

0 commit comments

Comments
 (0)