storage.castra.enemy is rebuilt only after an enemy research, and there is no on_configuration_changed, so ammo_tier can keep an item that no longer exists, e.g. kr-rifle-magazine after turning off K2's realistic weapons. fill_turrets then indexes prototypes.item[ammo].stack_size (base-upgrades.lua:89) and crashes. Calling update_castra_enemy_data() in on_configuration_changed and skipping a missing ammo prototype in fill_turrets would cover it.