[1.1.50] Crash When Setting Locomotive(/Wagon/Fluid Wagon) Weight to 0.0001

This subforum contains all the issues which we already resolved.
Post Reply
EnemySlinky
Manual Inserter
Manual Inserter
Posts: 2
Joined: Mon Feb 08, 2021 6:26 am
Contact:

[1.1.50] Crash When Setting Locomotive(/Wagon/Fluid Wagon) Weight to 0.0001

Post by EnemySlinky »

I have a simple mod that sets locomotive, wagon, and fluid wagon weight and max hp to 0.0001:

data.lua

Code: Select all

local locomotive = data.raw["locomotive"]["locomotive"]
locomotive.max_health = 0.0001
locomotive.weight = 0.0001

local cargo = data.raw["cargo-wagon"]["cargo-wagon"]
cargo.max_health = 0.0001
cargo.weight = 0.0001

fluid = data.raw["fluid-wagon"]["fluid-wagon"]
fluid.max_health = 0.0001
fluid.weight = 0.0001
When I use this mod, and load a map with a moving locomotive, the game crashes. When I use this mod and load a map without a moving locomotive, then place a locomotive and have it move by right clicking on the train ui, the game hangs, but does not crash. Entering the train and manually moving it does not cause the game to hang.

I've attached the save file, which is simply a set of trains moving back and forth. This file generates the crash very consistently as soon as it is opened. In other files, the crash doesnt happen immediately and I need to have the train move by ctrl clicking on the train UI.
Attachments
nyan test.zip
the save file. note that not all save files cause crashes, but going to the train UI minimap and ctrl clicking to move the train trains seems to generate crashes consistently
(2.19 MiB) Downloaded 91 times
factorio-current.log
(8.03 KiB) Downloaded 93 times

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2247
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.50] Crash When Setting Locomotive(/Wagon/Fluid Wagon) Weight to 0.0001

Post by boskid »

Thanks for the report.

I am considering this issue to be a wont fix. Its a "mod does stupid things, gets stupid results". I may do some safeguards that will prevent loading of such values.

Core of the issue is that there is an air resistance applied onto the speed of a train. Formula for this is following:

Code: Select all

this->speed *= (1 - this->airResistance / (this->weight / 1000.0));
Since this formula is supposed to only change positive speed into another but less positive speed, and negative speeed into less negative speed, basically entire right side of this expression should be positive. That means there is an assumption in the code that
(1 - trainAirResistance / (trainWeight / 1000.0)) >= 0
Which can be converted into this:
trainWeight >= 1000 * trainAirResistance
This crash happens because you have a train of a weight of 0.0006 and with airResistance of 0.0075. That means the expression becomes negative and speed of a train which was positive now becomes negative and train starts moving backward. Because of that, a train thinks it should go back, queries the path what is the next rail it should turn into but the path says it does not recognize this rail (path is for the other direction) and crashes with an error "Path is already off".

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2247
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.50] Crash When Setting Locomotive(/Wagon/Fluid Wagon) Weight to 0.0001

Post by boskid »

Ok. I decided to fix this issue in the following way: if this term becomes smaller than 0.001, it will use a value of 0.001 instead. That way a train will not crash the game due to change of direction but will be moving super slowly.

Post Reply

Return to “Resolved Problems and Bugs”