[boskid][1.1.53] Crash connecting rolling stock to neighbour while its being removed (on_train_created)
Posted: Thu Jan 27, 2022 5:10 pm
If you interact with a train carriage that is mid removal and get it to re-connect to another carriage you can crash the game. The on_train_created event gives you access to this mid removal stage.
Logic:
remove a locomotive from a 2 entity train. The game has to disconnect the loco first before removal. Using an event react to the train being changed (losing its loco) and tell the loco to re-join back to the train. Game crashes at this point.
Reproduction steps:
I found this as I noticed that the carriage didn't have a train attribute in the same setup and this surprised me (and crashed my mod). So I found this while quickly exploring the risks of this situation
Logic:
remove a locomotive from a 2 entity train. The game has to disconnect the loco first before removal. Using an event react to the train being changed (losing its loco) and tell the loco to re-join back to the train. Game crashes at this point.
Reproduction steps:
- load attached save (test.zip), just 2 locomotives on a rail connected as a train.
- run the attached Lua script to crash the game. It sets up the event function to try and rejoin the locomotives when their train changes and then removes one of the locomotives.
I found this as I noticed that the carriage didn't have a train attribute in the same setup and this surprised me (and crashed my mod). So I found this while quickly exploring the risks of this situation