Belt Balancer 2


Adds Balancer Parts, that can be put together, to balance all adjusting lanes. Updated for better performance and 2.0

Utilities
1 year, 1 month ago
2.0
18.2K
Logistics

b Non Recoverable Error

a day 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.

https://gyazo.com/d20e7c6462735adc257b7b690429d0c4

https://chatgpt.com/share/6938831f-7594-8013-9a81-089e45cd0901

New response