Gotcha. Thanks for the explanation and the notes you left in the files. This fixes the crash , but it skips over any of the vanilla infinite techs that are infinite from the first level onward. I made a list of the vanilla infinite techs and the last level they upgrade to before becoming infinite. All of the ones with a zero (no prior levels) are not affected by flattening.
["physical-projectile-damage"] = 5,
["stronger-explosives"] = 5,
["refined-flammables"] = 5,
["laser-weapons-damage"] = 5,
["follower-robot-count"] = 4,
["worker-robots-speed"] = 5,
["mining-productivity"] = 3,
["artillery-shell-range"] = 0,
["artillery-shell-speed"] = 0,
["electric-weapons-damage"] = 3,
["artillery-shell-damage"] = 0,
["railgun-shooting-speed"] = 0,
["railgun-damage"] = 0,
["health"] = 0,
["asteroid-productivity"] = 0,
["laboratory-productivity"] = 0,
["processing-unit-productivity"] = 0,
["scrap-recycling-productivity"] = 0,
["steel-plate-productivity"] = 0,
["low-density-structure-productivity"] = 0,
["plastic-bar-productivity"] = 0,
["rocket-fuel-productivity"] = 0,
["rocket-part-productivity"] = 0