Induction Charging deprecated

by Raeon

Power your equipment grid whilst in range of power poles, albeit at a price.

Content
3 years ago
1.1
21.7K
Armor

g Crashing With AAI

2 years ago

Consistent crash when giving orders to an AAI hauler, with or without an induction charger in it's grid (grid added by extra mod), though different errors.
No issues with any other vehicle (AAI or otherwise) as far as I have tested. I will write a quick patch if I find the time, likely just a few 'and X.valid' checks

Error with charger;
Error while running event Induction Charging::on_tick (ID 0)
LuaEntity API call when LuaEntity was invalid.
stack traceback:
[C]: in function 'index'
__Induction Charging
/control.lua:164: in function 'updateShadow'
Induction Charging/control.lua:280: in function <Induction Charging/control.lua:272>

Crash when without charger;
Error while running event Induction Charging::on_tick (ID 0)
LuaEntity API call when LuaEntity was invalid.
stack traceback:
[C]: in function 'index'
__Induction Charging
/control.lua:44: in function 'getID'
Induction Charging/control.lua:79: in function 'deleteTracker'
Induction Charging/control.lua:203: in function 'updateTracker'
Induction Charging/control.lua:287: in function <Induction Charging/control.lua:272>

2 years ago

The issue was with how AAI deletes it's hidden entities and this mod's entity validity checking;

The updateShadow() function checks that the shadow is valid, but not the entity is is following.
The updateTracker() function does check that the entity is valid, but deleteTracker() attempts to use the invalid entity.

Fix: wrap the above calls with a valid check & delete the tracker if it fails
Replaced function around line 272 with;
script.on_event(defines.events.on_tick, function(event)
local tick = event.tick
for id, tracker in pairs(trackers) do
if tracker.entity.valid then
-- Perform a minor update.
-- All we do is draw power from the shadow.
tickTracker(tracker)

        if id % shadowRate == tick % shadowRate then
            updateShadow(tracker)
        end

        -- Perform a full update based on the ID of the tracker.
        -- We do this instead of 'on_nth_tick(60, ...)' because this way we
        -- spread out the updates much better.
        if id % updateRate == tick % updateRate then
            updateTracker(tracker)
        end
    else
        if tracker.shadow and tracker.shadow.valid then
            tracker.shadow.destroy()
        end
        trackers[id] = nil 
    end
end

end)

2 years ago

This appears to still be an issue?

2 years ago
(updated 2 years ago)

lws'es fix works, but partially: it just prevents crashes but "disables" coils.

New response