Page 1 of 1

[0.16.51] Running LuaObjects through inspect's "process" will crash factorio to desktop

Posted: Sat Dec 22, 2018 2:43 am
by project6
The following code block in control.lua will run happily. However it will leave Factorio in a state where if you process the wrong bit of data, if you try to restart, or if you just try to quit to the main menu the game will crash to desktop (usually without a log):

Code: Select all

local inspect = require 'inspect'

local filter = function(item)
    return item
end

local function player_joined()
    global.make_inspect_crash_factorio = game.players[1]
    local dump_string = inspect(global, {process = filter})
    if dump_string then
        game.write_file('dump.lua', dump_string)
        game.print('dumped')
    end
end

script.on_event(defines.events.on_player_joined_game, player_joined)
Since inspect is bundled with Factorio I (incorrectly) assumed it wasn't going to be an issue to use it and all the options therein. In hindsight it makes total sense that you can't run a metatable or metatable elements or whatever through a function the way I did. Getting to that conclusion cost me about 6 hours time though because I wasn't sure where the issue was coming from.

It would be greatly appreciated if this restriction were documented in some way, even if it's just a 1-line throwaway comment at the top of inspect.lua itself.

Thanks.

Re: [0.16.51] Running LuaObjects through inspect's "process" will crash factorio to desktop

Posted: Sat Dec 22, 2018 5:47 am
by Rseding91
Thanks for the report. I don't know why we shipped the "inspect" library with Factorio. It shouldn't have been - I'm going to remove it for 0.17.

As for why it crashes I have no idea. The only reason it would crash is if the inspect library is doing something it shouldn't be - which seems likely. You can just use serpent.block() with pretty format options if you want to dump a table in human readable format.

Re: [0.16.51] Running LuaObjects through inspect's "process" will crash factorio to desktop

Posted: Sat Dec 22, 2018 11:40 am
by project6
You can just use serpent.block
The reason I use inspect for debugging now is serpent.block's previous failure. :(

Image

Thanks for addressing the bug I reported though. :)

Re: [0.16.51] Running LuaObjects through inspect's "process" will crash factorio to desktop

Posted: Sat Dec 22, 2018 5:18 pm
by Rseding91
Not sure what you're doing but it works perfectly fine for me: https://i.imgur.com/nxBNPjl.png

Re: [0.16.51] Running LuaObjects through inspect's "process" will crash factorio to desktop

Posted: Mon Feb 04, 2019 5:23 pm
by project6
We ended up finding out what the issue with serpent is: block() chokes on large numerical table keys
Is fine.
/c game.print(serpent.block({[2147483646] = true, [2147483647] = true}))

Is not fine.
/c game.print(serpent.block({[2147483647] = true, [2147483648] = true}))

2147483647 being int32.maxValue
Related: https://github.com/pkulchenko/serpent/issues/34

Re: [0.16.51] Running LuaObjects through inspect's "process" will crash factorio to desktop

Posted: Mon Feb 04, 2019 5:48 pm
by Rseding91
You don't want serpent.block since it's going to show you the data in a format that actually isn't in your table (sorting). You want serpent.dump which will give you what you actually have in the table in string form.

Regarding the sorting issue: I can probably just change the logic in the version of Lua we use to use 64 bit integers (since it's actually using them internally - just not in the code which formats numbers when using %d or %i).

Re: [0.16.51] Running LuaObjects through inspect's "process" will crash factorio to desktop

Posted: Mon Feb 25, 2019 6:34 pm
by project6
Found out today that you did indeed change the logic of the lua version and wanted to give my thanks. :)
(Was hard to be sure since this issue could have been marked resolved when `inspect` was removed)