Page 1 of 1
[2.1.7] Crash using create_entity to fast_replace RollingStock with same quality (RailConnectionDirection check fails)
Posted: Wed Jun 24, 2026 3:50 am
by robot256
When using LuaSurface::create_entity with fast_replace=true, the game will crash to desktop if the new entity is exactly the same as the old entity.
To reproduce: In Vanilla + Quality, create some track and a Normal wagon (or load the attached save). Select the wagon with the cursor, then run the following command:
Code: Select all
/c game.player.surface.create_entity{name="cargo-wagon", quality="rare", position=game.player.selected.position, direction=game.player.selected.direction, force=game.player.selected.force, fast_replace=true}
After this, you will be selecting a Rare wagon. Run the same command again:
Code: Select all
/c game.player.surface.create_entity{name="cargo-wagon", quality="rare", position=game.player.selected.position, direction=game.player.selected.direction, force=game.player.selected.force, fast_replace=true}
And the game crashes to desktop.
Re: [2.1.7] Crash using create_entity to fast_replace RollingStock with same quality (RailConnectionDirection check fail
Posted: Fri Jun 26, 2026 12:24 am
by robot256
FYI, this crash is still present in 2.1.8.
Re: [2.1.7] Crash using create_entity to fast_replace RollingStock with same quality (RailConnectionDirection check fail
Posted: Fri Jun 26, 2026 6:37 pm
by Loewchen
Re: [2.1.7] Crash using create_entity to fast_replace RollingStock with same quality (RailConnectionDirection check fail
Posted: Fri Jun 26, 2026 6:44 pm
by jurgy
Some additional info from the thread Loewchen linked:
- It's not (directly) related to fast_replace = true. The crash also happens if you place a second rolling stock on top of the other.
- It doesn't need to be the same rolling stock. I came across it first with two different locomotives
- It only happens when the rolling stock is placed in between tracks. Straight tracks are too short for this, but in curves it is possible to place a train without crashing if position just right.
- In that scenario two rolling stock entities are placed on top of each other. Even if fast_replace = true.
In the other thread I've linked a mod that has an on_built event that immediately tries to place a second locomotive to demonstrate the issue.
Re: [2.1.7] Crash using create_entity to fast_replace RollingStock with same quality (RailConnectionDirection check fail
Posted: Sat Jun 27, 2026 12:46 am
by robot256
I also have a case where the call to create_entity with fast_replace=true doesn't error or crash, but it deletes the old locomotive without creating a new one. I don't have a good way to reproduce it yet though. Maybe it has to do with the rail joint spacing that you suggest. I know it has to do with fast_replace because if fast_replace=false, the function correctly does not create a locomotive where there is no space for it, and leaves the old one in place.
Re: [2.1.7] Crash using create_entity to fast_replace RollingStock with same quality (RailConnectionDirection check fail
Posted: Mon Jun 29, 2026 8:11 pm
by Rseding91
Thanks for the report. This is now fixed for the next release. Two rolling stocks colliding with each other is not something the game is supposed to allow but the script case slipped through. For the next release the 2nd attempt at create_entity will fail due to colliding with the first one.