Rail Logistics Dispatcher

by Viidi

Adds a dispatcher (building) to automate railway logistics based on offers and requests. The mod is optimized for multi-delivery deliveries, has an intuitive interface and is published under a free license.

Content
1 year, 3 months ago
1.1
1.49K
Trains

g Corrupt Savegame, rescued by commenting out a line

8 months ago
(updated 8 months ago)

wave

This mod is very stable, even robust - my save is big, it has other mods in it, and there are no major issues, until save hour 1163, where a corrupt deleted provider station created a fatal error. I tried to add a if-clause to catch the error, but failed due to my lack of knowledge of LUA. I've ended up to comment the faulty line out, load the game, do what the error triggered, saved, removed the comment and played for another hours without any issue. I'm writing this to give a level of ease to the priority, as I'm again am able to access my save and I'm not in severe need of immediate help :)

So what happend?

There was a station which requesting Sodium hydroxide solution. A train fulfilling this delivery throws the following error:

The mod Rail Logistics Dispatcher (0.0.18) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event RailLogisticsDispatcher::on_train_changed_state (ID 25)
RailLogisticsDispatcher/script/SurClass.lua:581: attempt to call method 'removeDeliveryFromStop' (a nil value)
stack traceback:
RailLogisticsDispatcher/script/SurClass.lua:581: in function 'removeDelivery'
RailLogisticsDispatcher/script/StopClass.lua:585: in function 'trainDepart'
RailLogisticsDispatcher/script/TrainClass.lua:461: in function 'handleDeparture'
RailLogisticsDispatcher/control.lua:172: in function <RailLogisticsDispatcher/control.lua:167>

When trying to remove the train differently, a similar error appears:

The mod Rail Logistics Dispatcher (0.0.18) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event RailLogisticsDispatcher::on_player_mined_entity (ID 67)
RailLogisticsDispatcher/script/SurClass.lua:581: attempt to call method 'removeDeliveryFromStop' (a nil value)
stack traceback:
RailLogisticsDispatcher/script/SurClass.lua:581: in function 'removeDelivery'
RailLogisticsDispatcher/script/SurClass.lua:567: in function 'removeDeliveriesBy'
RailLogisticsDispatcher/script/SurClass.lua:641: in function 'removeTrain'
RailLogisticsDispatcher/script/TrainClass.lua:438: in function 'handleRemoved'
RailLogisticsDispatcher/control.lua:154: in function <RailLogisticsDispatcher/control.lua:147>

So, in case you have this error, what helped me is the following:
- unzip the mod, so that it loads the files instead of the zip.
-- i need the move the folder and remove the zip for this.
- go to __/script/SurClass.lua:581 and -- comment the line out.
- load game, mine the train, save game, use regular mod.zip again.
-- I have no idea if there are follow up error due to this fix, but for now it's better than a fatal.

But how did I end up in that situation?
tbh - I don't know. But I have an assumption:
- In the hours before the event I've restructured a lot of stations. Picking them up, placing them somewhere else, etc.
- Train was otw.
- I've removed the provider.
- Train waited for a few hours due to train issues.
- Somewhere the connection to the provider was lost.
- When the delivery has to be removed, the provider stats are updated, but there is no provider, but a nil value.

When removing a station i usually remove the requests of that station and wait until all running requests are fulfilled. In case of fluids, I flush the stuff because I don't want to turn a requester into a provider. Once the trains are not inbound anymore I deconstruct the station, mostly with bots.

I've done that several times without issues, but I think this is the way the corrupt train came to existence. Still, I have no proof.

Savegame: https://cdn.discordapp.com/attachments/1118036159868698624/1143774276135165983/angel5.zip
When loaded in, the train to your right is the corrupt one. Mining it gives you the error. The train to your left is stuck, and when you send it away and wait until the Sodium hydroxide solution is unloaded, you get the error.

Ah, and when you try to open the GUI of that station, you will get this error:
The mod Rail Logistics Dispatcher (0.0.18) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event RailLogisticsDispatcher::on_gui_opened (ID 88)
LuaEntity API call when LuaEntity was invalid.
stack traceback:
[C]: in function 'index'
__RailLogisticsDispatcher
/script/DispGui.lua:962: in function 'updateStopInfo'
RailLogisticsDispatcher/script/DispGui.lua:127: in function 'open'
RailLogisticsDispatcher/script/DispGui.lua:84: in function 'handleGuiOpened'
RailLogisticsDispatcher/control.lua:87: in function <RailLogisticsDispatcher/control.lua:84>

And mining the Station throws this one:
The mod Rail Logistics Dispatcher (0.0.18) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event RailLogisticsDispatcher::on_player_mined_entity (ID 67)
RailLogisticsDispatcher/script/SurClass.lua:581: attempt to call method 'removeDeliveryFromStop' (a nil value)
stack traceback:
RailLogisticsDispatcher/script/SurClass.lua:581: in function 'removeDelivery'
RailLogisticsDispatcher/script/SurClass.lua:567: in function 'removeDeliveriesBy'
RailLogisticsDispatcher/script/SurClass.lua:287: in function 'updateStop'
RailLogisticsDispatcher/script/SurClass.lua:609: in function 'removeStop'
RailLogisticsDispatcher/script/DispClass.lua:156: in function 'handleRemoved'
RailLogisticsDispatcher/control.lua:152: in function <RailLogisticsDispatcher/control.lua:147>

I hope this information finds you well, I'm available for questions!

I still highly recommend your mod, and taking a look into the code... it's beautiful :)

PS: I've streamed the whole thing, so in case you want to watch what I did before and during the incident: https://www.twitch.tv/videos/1905377926?t=6h45m23s (German)

8 months ago

Ooo! Many thanks for the investigation and for the detailed description.
I will try to find time to find and fix this bug, including already saved games.

I hope you and your viewers weren't too disappointed by the bugs in my mod.

5 months ago

I am getting the same bug, the way i "got there" was that i removed the trains that where on the way to get the items but they did never pick up the items because i had some signal issues in the pickup station that made alot of trains go for the station when they should not have, my best guess is that when i removed the train the delivery was still "active" and not removed from the stations list, and now when i try and remove the stop or the dispatcher it tries to find the train that had the route and fails on that task.

Just my thoughts on that.. :)

New response