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.