Page 1 of 1

[0.17.74] Game crash when exiting /editor

Posted: Sat Oct 26, 2019 10:23 pm
by SimonFlapse
My game has crashed mulitple times while leaving the scenario editor using the /editor command

It seems to have something to do with a mismatch in positions: I can often provoke this crash by trying to walk while the /editor command is restoring my character in a game with less than 60 updates per seconds

Code: Select all

100.748 Error Player.cpp:1040: Controller position and given position don't match: {-0.0195312500, 0.0000000000} != {-5.2304687500, 3.6015625000}.
It is especially annoying since I keep loosing my custom lua snippets in the lua tab of the editor every time.

Re: [0.17.74] Game crash when exiting /editor

Posted: Sun Oct 27, 2019 12:23 pm
by Rseding91
Thanks for the report. Do you have some reliable way to reproduce the crash? I notice in the log file what ever save you were using had custom control.lua scripting which might contribute to the issue.

Walking while leaving the editor should have zero impact since leaving the editor is done all at once and walking happens after it finishes.

Re: [0.17.74] Game crash when exiting /editor

Posted: Sun Oct 27, 2019 2:03 pm
by SimonFlapse
I don't have a reliable way of reproducing it at the moment.

However I believe its happening because I'm entering /editor while my controller isn't a character and when I'm exiting /editor (and the game resumes) the custom scripting creates a character for my player and changes the controller type to character.

Re: [0.17.74] Game crash when exiting /editor

Posted: Sun Oct 27, 2019 4:42 pm
by Klonan
SimonFlapse wrote:
Sun Oct 27, 2019 2:03 pm
I don't have a reliable way of reproducing it at the moment.

However I believe its happening because I'm entering /editor while my controller isn't a character and when I'm exiting /editor (and the game resumes) the custom scripting creates a character for my player and changes the controller type to character.
Can you attach the script or save game with the script?

Re: [0.17.74] Game crash when exiting /editor

Posted: Mon Oct 28, 2019 2:33 pm
by SimonFlapse
I've attached a save that produces the crash. I haven't had time to reproduce it in a freeplay scenario

The code that I suspect is part of the crash is located in map_gen/maps/space-race/scenario.lua function at line 210.

This function gets called 600 ticks after the condition at line 425 is satisfied (Checking if the map have changed)

The character is destroyed in the script located in map_gen/maps/space-race/lobby.lua in the function at line 132 (Which is triggered by the on_player_created event)

To reproduce using the attached save:
- Press the 'Join Union of Factory Employees' button
- Enter /editor as soon as possible after being teleported to another surface
- Using the editor mode fly west until you reach a market (x = -403, y = 0)
- Wait for the custom map generation to change the map (It should add some ores and some out-of-map tiles) (Stay in editor mode)
- use /editor to exit editor mode
- Move around and toggle /editor mode until crash

The custom script's logic, in broad terms:

on_player_created, destroy character and set the players controller to ghost
After some time, some condition is satisfied, triggering:
a function that creates a character entity for the player and sets the controller type to character

I hope this helps, although it contains a heavy scenario

Re: [0.17.74] Game crash when exiting /editor

Posted: Mon Oct 28, 2019 2:36 pm
by Klonan
Thats a big hefty script,

Can you try narrowing it down to just 1 script file for me?
Or just the 1 script event handler that cans reproduce the issue?

Re: [0.17.74] Game crash when exiting /editor

Posted: Mon Oct 28, 2019 2:53 pm
by SimonFlapse
I've given it a quick shot, to narrow it down to a single file (That depends on some other custom scripts)

The script is located in map_gen/maps/default.lua

I hope this is enough.

Code: Select all

local Event = require 'utils.event'
local Token = require 'utils.token'
local Task = require 'utils.task'

local delayed_restore_character = Token.register(function() -- A way of storing the function to prevent desyncs (The function restores the character)
    for i = 1, #game.players do
        local player = game.players[i]
        local character = player.character
        if character then
            character.destroy()
        end
        player.set_controller {type = defines.controllers.god}
        player.create_character()
    end
end)

local function on_player_created(event)
    local player = game.get_player(event.player_index)

    local character = player.character
    if character and character.valid then
        player.character.destroy()
    end
    player.set_controller {type = defines.controllers.ghost}
    Task.set_timeout_in_ticks(600, delayed_restore_character, {}) -- Delays restoring the character by 600 ticks
end

Event.add(defines.events.on_player_created, on_player_created) -- Registers the on_player_created function as a callback when the on_player_created_event is triggered
Edit: I have uploaded a new log and dump so that it doesn't contain irrelevant information

Re: [0.17.74] Game crash when exiting /editor

Posted: Mon Oct 28, 2019 3:10 pm
by Klonan
I can't seem to get it to crash,

What are the exact steps I need to make in order to reproduce the error (with the minimal save game)

Re: [0.17.74] Game crash when exiting /editor

Posted: Mon Oct 28, 2019 3:19 pm
by SimonFlapse
Steps:
Restart the save
repeat:
{
Type /editor
Move around
}

Oversized GIF showing the steps: https://drive.google.com/open?id=1Q4QqO ... LmGm5FFvIL
MP4 file: https://drive.google.com/open?id=1ltU-5 ... 3Xmq888Oi4

Re: [0.17.74] Game crash when exiting /editor

Posted: Mon Oct 28, 2019 5:07 pm
by Rseding91
Thanks for the reproduction steps. It's now fixed for the next version of 0.17.