Page 1 of 1

[0.17.39] get_inventory() fails

Posted: Thu May 16, 2019 3:59 am
by Oarc
Hello,

I am seeing this failure occasionally but I don't know how to reproduce it:
Linux headless server, running custom scenario, no mods, map was started sometime between .35 and .37 updates I think.

Code: Select all

69711.329 Error ServerMultiplayerManager.cpp:92: MultiplayerManager failed: "The scenario level caused a non-recoverable error.
Please report this error to the scenario author.

Error while running event level::on_built_entity (ID 6)
real number expected got nil.
stack traceback:
        ..._0.17/factorio/temp/currently-playing/lib/oarc_utils.lua:697: in function 'AutofillTurret'
        ..._0.17/factorio/temp/currently-playing/lib/oarc_utils.lua:955: in function 'Autofill'
        ...actorio_0.17/factorio/temp/currently-playing/control.lua:216: in function <...actorio_0.17/factorio/temp/currently-playing/control.lua:214>
stack traceback:
        [C]: in function 'get_inventory'
        ..._0.17/factorio/temp/currently-playing/lib/oarc_utils.lua:697: in function 'AutofillTurret'
        ..._0.17/factorio/temp/currently-playing/lib/oarc_utils.lua:955: in function 'Autofill'
        ...actorio_0.17/factorio/temp/currently-playing/control.lua:216: in function <...actorio_0.17/factorio/temp/currently-playing/control.lua:214>
69711.329 Info ServerMultiplayerManager.cpp:776: updateTick(3474305) changing state from(InGame) to(Failed)
69711.329 Quitting: multiplayer error.
The line in question where the failure occurs is this:

Code: Select all

local mainInv = player.get_inventory(defines.inventory.character_main)
I have used this code for quite awhile (years) and never had a failure before until .38/.39 updates. The only change I made was during the player->character renaming I think.

My expectation is that regardless of the player's state, character is dead/alive/god-mode, the get_inventory function should at worst return nil.

I am not writing or changing defines.inventory anywhere. I am using a scenario only, no mods.

I am not sure if this is a bug, but from my understanding of this error report, it is saying that I am passing get_inventory nil, instead of a number?

Re: [0.17.39] get_inventory() fails

Posted: Thu May 16, 2019 9:07 am
by kovarex
This looks, like the inventory index wasn't passed and nil was passed instead. I don't really know how could this happen, but we would need more isolated case to figure it out.

Re: [0.17.39] get_inventory() fails

Posted: Thu May 16, 2019 11:48 am
by Oarc
Yeah I agree, I just couldn't figure out a way to reproduce it.

The only thing I can say for sure is that I've used that specific code for quite a long time, and it's only recently started to fail since the last 1 or 2 updates.

I'll let you know if I'm able to reliably repro or if I have any other useful info.

Re: [0.17.39] get_inventory() fails

Posted: Fri May 17, 2019 4:07 am
by Oarc
@Kovarex

I found a way to reproduce the problem, but I feel like it's a corrupted save file or something?
https://transfer.sh/1wAPq/oarc-save-broken.zip

If you load that save, and try to place a turret, it causes the error immediately.

I just have no idea how my scenario / map file got like this in the first place. It's not like my server lost power mid-save or anything, even then, I'd expect it just fail to load instead of this weird failure.

If I start a fresh game with the same scenario code, I don't think I see the error anymore.

Re: [0.17.39] get_inventory() fails

Posted: Fri May 17, 2019 9:43 am
by Bilka
Oarc wrote:
Fri May 17, 2019 4:07 am
I found a way to reproduce the problem, but I feel like it's a corrupted save file or something?
https://transfer.sh/1wAPq/oarc-save-broken.zip
That save contains old scenario code, line 697 of oarc_utils is "local mainInv = player.get_inventory(defines.inventory.player_main)" which leads to the error in game versions that have the player -> character rename.

Re: [0.17.39] get_inventory() fails

Posted: Fri May 17, 2019 11:03 am
by Oarc
Ah... I didn't catch that, sorry for wasting your time, thanks for the help!