[2.1.7] Crash using create_entity to fast_replace RollingStock with same quality (RailConnectionDirection check fails)

This subforum contains all the issues which we already resolved.
robot256
Smart Inserter
Smart Inserter
Posts: 1372
Joined: Sun Mar 17, 2019 1:52 am
Contact:

[2.1.7] Crash using create_entity to fast_replace RollingStock with same quality (RailConnectionDirection check fails)

Post 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.
Attachments
script_fast_replace_wagon_test.zip
(1.16 MiB) Downloaded 2 times
factorio-dump-current.dmp
(1.17 MiB) Downloaded 5 times
factorio-current.log
(12.11 KiB) Downloaded 11 times
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
robot256
Smart Inserter
Smart Inserter
Posts: 1372
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: [2.1.7] Crash using create_entity to fast_replace RollingStock with same quality (RailConnectionDirection check fail

Post by robot256 »

FYI, this crash is still present in 2.1.8.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
User avatar
jurgy
Inserter
Inserter
Posts: 48
Joined: Wed Feb 27, 2019 5:55 pm
Contact:

Re: [2.1.7] Crash using create_entity to fast_replace RollingStock with same quality (RailConnectionDirection check fail

Post 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.
robot256
Smart Inserter
Smart Inserter
Posts: 1372
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: [2.1.7] Crash using create_entity to fast_replace RollingStock with same quality (RailConnectionDirection check fail

Post 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.
My mods: Multiple Unit Train Control, RGB Pipes, Shipping Containers, Rocket Log, Smart Artillery Wagons.
Maintainer of Auto Deconstruct, Cargo Ships, Vehicle Wagon, Honk, Shortwave.
Rseding91
Factorio Staff
Factorio Staff
Posts: 17037
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.1.7] Crash using create_entity to fast_replace RollingStock with same quality (RailConnectionDirection check fail

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Resolved Problems and Bugs”