Fix iteration error when splitting transfers.

If one type of unit is zeroed but there are still other units to check
in the dict, the dict will have changed size during iteration. Iterate
on a copy of the dict instead.

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/2773.
This commit is contained in:
Dan Albert 2023-03-31 16:00:07 -07:00
parent af2e195f90
commit 5c72e0754a

View File

@ -616,7 +616,10 @@ class PendingTransfers:
raise ValueError
units = {}
for unit_type, remaining in transfer.units.items():
# If one type of unit is zeroed but there are still other units to check in the
# dict, the dict will have changed size during iteration. Iterate on a copy of
# the dict instead.
for unit_type, remaining in dict(transfer.units).items():
take = min(remaining, size)
size -= take
transfer.take_units(unit_type, take)