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
2 months ago
0.17 - 1.1
2.98K
Transportation Combat Logistic network Circuit network

b [Fixed?] Crash when driving into a tree

5 months ago
(updated 5 months ago)

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

Error while running event autodrive::on_entity_damaged (ID 103)
autodrive/scripts/vehicle_functions.lua:3103: attempt to index local 'cause' (a nil value)
stack traceback:
autodrive/scripts/vehicle_functions.lua:3103: in function 'on_entity_damaged'
autodrive/scripts/event_handlers.lua:1656: in function <autodrive/scripts/event_handlers.lua:1623>

Let me know if you need a save file.

5 months ago

Thanks for the report! Yes, I guess a save file would be helpful to understand how you got to that line. There are some checks before that to make sure that 'cause' exists but they seem to be faulty.

5 months ago
(updated 5 months ago)

Sorry for the long delay :)

Just sent you a forum PM with the save (my username is different, but for verification I sent it Mon Jul 01, 2024 19:27 CEST)

I have a lot of mods loaded for that save, so autodrive might just be incompatible with one or a few. Anyway, the dependencies tab should allow you to list conflicting mods.

5 months ago

Just sent you a forum PM with the save (my username is different, but for verification I sent it Mon Jul 01, 2024 19:27 CEST)

Thanks, I've found it! :-)

I have a lot of mods loaded for that save, so autodrive might just be incompatible with one or a few. Anyway, the dependencies tab should allow you to list conflicting mods.

Yep, >300 mods really is "a lot of mods", but I've found the culprit! Schall Tank Woodcutting will destroy trees if they suffer impact damage from an entity based on a "car" prototype.

Usually, Autodrive will be first to get events, so if a vehicle hurts a tree without killing it, Autodrive will let the vehicle bounce. However, if Schall Transport Group also is active, Schall Tank Woodcutting will get the event first and destroy the damaged tree.

Now, for each crash there are several events that may (or may not) be raised: A damaging B, B damaging A, A damaging A, and B damaging B. If Tank Woodcutting is loaded first, Autodrive won't get an event for the damaged tree (it has already been destroyed). However, it will get the event for the vehicle taking damage from the tree -- but as the tree isn't there anymore, event.cause is nil and therefore we get the crash.

Unfortunately, Schallfalke hasn't been on the forum or updated his mods for over a year. I've sent him a PM, but I guess there won't be any reply soon, if ever. The best I can do is add a check to my event handler so that I won't try to run the bouncing code if there is no event.cause. However, this means the vehicle will get the vanilla behavior and come to a full stop as soon as it has crashed with a tree. (This could also happen with rocks, depending on a setting of Schall Tank Woodcutting.)

As a temporary fix until I'm ready to release the next version, you can add "? autodrive" to the dependencies of Schall Tank Woodcutting (just edit its info.json), so Autodrive will always be loaded first and get the event before the other mod can destroy the damaged entity.

5 months ago
(updated 5 months ago)

Thanks for the investigation, I hope it didn't take too long.

So somehow because schalltankwoodcutting destroys the tree, the event is modified by the game so it doesn't have a cause anymore (because the tree was removed)? IMHO that's weird game behavior, you would expect the event to be stopped from propagating to other mods somehow.

I will see what happens when I add a nil check on cause myself, and then add the optional dependency if it's not to my liking :)

5 months ago

Tanks for the investigation, I hope it didn't take too long.

It wasn't obvious that the woodcutting mod would be loaded first if the transport group mod was active (I still can't explain why this happens), so it took a while … :-)

So somehow because schalltankwoodcutting destroys the tree, the event is modified by the game so it doesn't have a cause anymore (because the tree was removed)? IMHO that's weird game behavior, you would expect the event to be stopped from propagating to other mods somehow.

The first event (where the tank is the cause of the crash) isn't propagated to Autodrive, so I can't take precautions that the second (where the vehicle itself gets damaged from colliding with the tree) will be skipped.

5 months ago

It wasn't obvious that the woodcutting mod would be loaded first if the transport group mod was active (I still can't explain why this happens), so it took a while … :-)
Yeah, that must have been quite frustrating, like WTF :D

The first event (where the tank is the cause of the crash) isn't propagated to Autodrive, so I can't take precautions that the second (where the vehicle itself gets damaged from colliding with the tree) will be skipped.

That makes sense.

By the way, I decided to also play with https://mods.factorio.com/mod/one-more-hovercraft and https://mods.factorio.com/mod/DMV_Directional_Movement_Vehicles, which I think are pretty cool. I added "if not event.cause then return end" to the top of the handler. And when using the car (which is now a hovercraft) it no longer crashes into trees, it just wobbles around them (which might not be a bug, but a feature - or it might be the hovercraft mod, I don't know). I may even install the tank woodcutting mod.

I haven't tested the autodrive sensors with those mods loaded yet however. If I find any problems I will let you know :)

5 months ago
(updated 5 months ago)

By the way, I decided to also play with https://mods.factorio.com/mod/one-more-hovercraft and https://mods.factorio.com/mod/DMV_Directional_Movement_Vehicles, which I think are pretty cool. I added "if not event.cause then return end" to the top of the handler. And when using the car (which is now a hovercraft) it no longer crashes into trees, it just wobbles around them (which might not be a bug, but a feature - or it might be the hovercraft mod, I don't know). I may even install the tank woodcutting mod.

DMV will replace the hovercraft with a spider-vehicle that's looking just like the original entity. But for some reason, it's not working as expected: Pathing will return no path, and collisions won't raise on_entity_damaged, so bouncing and tree-healing won't work. I'm not sure what's causing that, at least pathing should work (it does with the vanilla spidertron).

EDIT: Duh, just noticed that collision_masks are passed on as argument to path finding. I guess that could be the reason why no path is returned -- still have to check, though.

5 months ago

Please try version 1.1.15!

2 months ago

Please give Schall Tank Woodcutting (Autodrive fix) a try! It has an optional dependency on Autodrive so that it won't destroy stuff before Autodrive has a chance to act. Moreover, it will add as many harvested items to the vehicle trunk as can be used by the vehicle. You must update Autodrive to at least version 1.1.16 to take advantage of this.

New response