Autodrive

by Pi-C

Car equipment for train avoidance, logistic network integration, circuit network connectivity, fuel refill, ammo reload, vehicle repair, radio control, enemy targeting, and gate control.

Content
a month ago
0.17 - 2.0
3.27K
Transportation Combat Logistic network Circuit network

b [Pending] Crash when manually switching weapons with enemy sensor active

5 days ago

When you drive a tank with enemies in the range of your current weapon and switch to a different weapon, the game crashes. Tested on modded and unmodded (besides autodrive ofc) games with the same error:

The mod Autodrive (2.0.4) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event autodrive::on_tick (ID 0)
core/lualib/util.lua:26: bad argument #1 of 2 to 'pairs' (table expected, got userdata)
stack traceback:
[C]: in function 'pairs'
core/lualib/util.lua:26: in function 'compare'
autodrive/scripts/vehicles.lua:4574: in function 'has_loaded_gun'
autodrive/scripts/driving.lua:342: in function 'check_crons'
autodrive/scripts/driving.lua:871: in function 'tick_vehicle'
autodrive/scripts/event_handlers.lua:1318: in function <autodrive/scripts/event_handlers.lua:1272>

This doesn't happen every time, and seems like it's most likely to happen when the gun you're switching away from is about to fire (i.e. the turret isn't moving to acquire a new target and the weapon isn't on cooldown). But I'm conjecturing here, I don't know exactly how to reproduce this. That being said, if you just fiddle with switching the guns, you should run into this pretty quickly.

4 days ago

Thanks! I haven't tested this, but I believe if you comment lines 4573/4574 of script/vehicles.lua everything should work again:

AD.show("state.gun.item == gun", (state and state.gun and state.gun.item and gun) and
                                  util.table.compare(state.gun.item, gun))

should become

-- AD.show("state.gun.item == gun", (state and state.gun and state.gun.item and gun) and
--                                  util.table.compare(state.gun.item, gun))

This is just logging the result of a comparison. Not sure why this is still in the code, as there is no such comparison following it. It must be ancient because I try to compare tables – but since Factorio 2.0, prototypes, items, entities, etc. are of type userdata instead of table.

4 days ago

You're right, commenting the lines out seems to make the issue go away, I haven't been able to reproduce it afterwards.

New response