I needed to move a power pole that was providing power to one of my circuit repeaters. While the repeater was without power, I received the following error:
9518.748 Error MainLoop.cpp:1468: Exception at tick 124398900: The mod Multi Circuit Repeater (1.0.21) caused a non-recoverable error.
Please report this error to the mod author.
Error while running event Multi_Circuit_Repeater::on_tick (ID 0)
real number expected got userdata.
stack traceback:
[C]: in function 'get_object_by_id'
Multi_Circuit_Repeater/control.lua:351: in function 'UpdateTowerPowerStates'
Multi_Circuit_Repeater/control.lua:410: in function <Multi_Circuit_Repeater/control.lua:404>
9526.363 Info AppManager.cpp:353: Deleting active scenario.
I can easily recreate the error by placing and powering two repeaters, then remove power from one of them and wait about 15 seconds.
My fix is to use the same pattern already used in UnifiedRenderCleanup — check whether the stored value is a number or userdata before calling get_object_by_id. Here's my patched section (lines 349-354):
local id = storage.wct_overlays[radar.unit_number]
if id then
if type(id) == "number" then
local obj = rendering.get_object_by_id(id)
if obj and obj.valid then obj.destroy() end
elseif type(id) == "userdata" then
if id.valid then id.destroy() end
end
storage.wct_overlays[radar.unit_number] = nil
end