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)