Belt Balancer

by asdff45

Adds Balancer Parts, that can be put together, to balance all adjusting lanes.

Content
5 years ago
0.17 - 1.1
50.6K
Logistics

b Non-recoverable error caused by invalid LuaTransportLine references (Belt Balancer 2 v2.0.9)

6 days ago

Hello, I’m reporting a repeatable crash occurring in Belt Balancer 2 (2.0.9). The mod throws a non-recoverable error when a LuaTransportLine becomes invalid but is still processed during the balancer update tick.

Error message:
The mod Belt Balancer 2 (2.0.9) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event belt-balancer-2::on_nth_tick(4)
LuaTransportLine API call when LuaTransportLine was invalid.
stack traceback:
[C]: in function 'len'
__belt-balancer-2
/objects/balancer.lua:203: in function 'run'
belt-balancer-2/helper/message-handler.lua:33: in function <belt-balancer-2/helper/message-handler.lua:31>

What triggers it

The crash consistently happens after belts connected to an active balancer are:

mined

rotated

upgraded with bots

or blueprint-replaced

When this happens, one or more LuaTransportLine references in the internal lane table become invalid. On the next on_nth_tick(4) update, the script attempts #lane or lane[1] on an invalid line, which triggers the unrecoverable exception.

Root cause

At line ~203 in objects/balancer.lua, the code assumes all stored transport lines are still valid:
if #lane > 0 then
local item = lane[1]
table.insert(balancer.buffer, stablize_item_stack(item))
lane.remove_item(item)

If lane.valid is false, any of these calls (#lane, lane[1], remove_item) produce the fatal error.

Proposed fix (tested and working)

Adding lane.valid checks around all lane operations prevents the crash and allows balancers to safely handle belt removal.

Working patch example:
if lane and lane.valid and #lane > 0 then
local item = lane[1]

if item then
    table.insert(balancer.buffer, stablize_item_stack(item))

    if lane.valid then
        lane.remove_item(item)
    end
end

if lane.valid and #lane > 0 then
    next_lanes[k] = lane
    next_lane_count = next_lane_count + 1
end

end
This ensures the mod skips invalidated lines gracefully instead of causing a hard crash.

Result

After applying this validation check, the issue is fully resolved and the world loads and runs normally with no further errors.

6 days ago

I am not the developer of Belt Balancer 2, please report issues to the author.

3 days ago

Who is the author if you posted it...

3 days ago

I haven't, you are at the repo of v1. Go to https://mods.factorio.com/mod/belt-balancer-2

a day ago

Thanks!

New response