Any Planet Start


Start on any of the first three planets: Vulcanus, Gleba, or Fulgora. Choose your planet in the startup mod settings before starting a new game. Compatible with many modded planets!

Content
15 days ago
2.0 - 2.1
43.1K
Factorio: Space Age Icon Space Age Mod
Planets Environment

b ✅ Error when migrating to 2.1 while removing Pelagos

a month ago

When updating a multiplayer (2 players) save from 2.0, i got the error below.
The save had a decent amount of mods, can post them if needed. Could send the save itself too.
Crucially, Pelagos was removed while migrating as it's not yet on 2.1.

The mod Any Planet Start (1.2.6) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event any-planet-start::on_player_changed_surface (ID 61)
any-planet-start/control.lua:125: attempt to index field 'character' (a nil value)
stack traceback:
any-planet-start/control.lua:125: in function 'respawn_player'
any-planet-start/control.lua:204: in function <any-planet-start/control.lua:200>

15 days ago

Same crash here, and one thing that matters for the fix.

Crash

Error while running event any-planet-start::on_player_changed_surface (ID 61)
any-planet-start/control.lua:125: attempt to index field 'character' (a nil value)
control.lua:125: in function 'respawn_player'
control.lua:204: in function <control.lua:200>

Exception at tick 40276281: The mod Any Planet Start (1.2.6) caused a non-recoverable error.
MultiplayerManager failed: "The mod Any Planet Start (1.2.6) caused a non-recoverable error."

Environment: Factorio 2.1.24 (build 87808), dedicated server, ~240 mods.
Trigger: removed castra-prime (a planet mod) from an existing multiplayer save,
aps-planet was none. Crash happens the moment a player enters the map.
Same class of report as the Pelagos one above.

Root cause 1 - on_player_changed_surface has no surface_index

The event only provides name, tick and player_index. So this at
control.lua:203:

if event.surface_index == nil or player.controller_type == defines.controllers.ghost then
    respawn_player(player)
end

...is always true, and respawn_player() runs on every single surface change.
It also teleports players to {0, 0} whenever they switch surfaces on Nauvis.

Root cause 2 - player.character can be nil

control.lua:124:

if player.controller_type == defines.controllers.character then
    local new_position = surface.find_non_colliding_position(
        player.character.prototype.name, {0, 0}, 1000, 0.5)

controller_type is already character while player.character is still nil -
which is exactly the state after a surface is deleted and the character is
being recreated.

Please don't fix it with a nil check alone - it causes desync

The obvious patch:

if player.controller_type == defines.controllers.character and player.character then

stops the crash, but desyncs multiplayer within about a second of joining:

Multiplayer desynchronisation: crc test (heuristic) failed for crcTick(40971347)
serverCRC(208528490) localCRC(850900939)

Cause: player.character is not visible at the same moment on client and server.

  • server: character exists -> runs find_non_colliding_position(...) -> position A
  • client: character is nil -> skips the branch -> position stays {0, 0}

Different teleport targets on the two ends -> state divergence.
Player joined at tick 40971289, desync fired at 40971347.

Fix that works

Do not read player.character at all - use the fixed prototype name, so both
ends compute exactly the same result:

-- control.lua:123
local position = {x = 0, y = 0}
local new_position = surface.find_non_colliding_position("character", {0, 0}, 1000, 0.5)
if new_position then
    position = new_position
else
    local name = surface.planet and surface.planet.prototype.localised_name
        or surface.platform and surface.platform.name
        or surface.localised_name or surface.name
    player.print({"", "[Any Planet Start] Could not find non-colliding spawn position on ", name, "."})
end

And drop the dead condition:

-- control.lua:203
if player.controller_type == defines.controllers.ghost then
    respawn_player(player)
end

Result, tested with 1 server + 1 client on 2.1.24:

  • no crash when a planet mod is removed from a save
  • no desync
  • version stays 1.2.6 and no data-phase file is touched, so
    Checksum of any-planet-start is still 1455086543

Thanks - the mod itself works great, this is the only blocker for removing a
planet mod from a running save.

15 days ago

Not sure how I missed the first post, sorry about that.
Thanks for the report, fixed in 1.2.7

The only thing the AI got right was the fact that player.character could be nil; Its reasoning every step of the way was completely wrong.
Hard coding the character name is also bad for mod compatibility, I solved this in a different way.

New response