science-spread crashes on load: invalid order function for sorting
Factorio 2.1.24, science-spread 0.9.2.
sorting.lua:66: invalid order function for sorting
sorting.lua:66 (table.sort of lab.inputs)
data-final-fixes.lua:225
Cause: sort_pack() isn't a valid comparator when order is missing.
if order1 == nil then return true end
if order2 == nil then return false end
When both entries are nil, it returns true in both directions, so Lua's
table.sort raises "invalid order function for sorting". The "null check"
in the changelog is what breaks it.
orders[x] goes nil for any lab input that is not in data.raw["item"] or
data.raw["tool"] - e.g. repair-pack (repair-tool) and raw-fish (capsule).
Those come from labs that consume non-science items:
- ribbonia: ribbonia-maintenance-station
(inputs include repair-pack, raw-fish, water-barrel, ...)
- Nexus: omega-lab copies other labs' inputs into itself
- harene-infused-omega-lab gets them the same way
So the crash needs just two non-item inputs in one lab. Logged with an
instrumented build:
lab input without sort key: repair-pack (no prototype) used by labs:
omega-lab, ribbonia-maintenance-station, harene-infused-omega-lab
Suggested fix: make the comparator a strict weak order, e.g.
local function less(a, b) -- nil sorts last
if a == b then return false end
if a == nil then return false end
if b == nil then return true end
return a < b
end
if order1 == nil or order2 == nil then
if order1 == nil and order2 == nil then return p1 < p2 end
return order1 ~= nil
end
Same for sort_ingredient (it returns false for both nil cases, which is
safe but inconsistent with sort_pack).