[0.15.37] Crash related to copying game objects

We are aware of them, but they have low priority. We have more important things to do. They go here in order not to take space in the main bug thread list.
Post Reply
blueblue
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Tue Apr 11, 2017 7:39 pm
Contact:

[0.15.37] Crash related to copying game objects

Post by blueblue »

I accidentally tried to copy a table that has a player as a member (using a custom copy function). The game outputs an error into chat which is fine, then crashes which probably isnt. To reproduce in single-player 0.15.37:

Code: Select all

/c 
function copy(obj, seen)
    if type(obj) ~= 'table' then return obj end
    if seen and seen[obj] then return seen[obj] end
    local s = seen or {}
    local res = setmetatable({}, getmetatable(obj))
    s[obj] = res
    for k, v in pairs(obj) do res[copy(k, s)] = copy(v, s) end
    return res
end  
copy(game.player)
unique_2 on discord and mod portal

Rseding91
Factorio Staff
Factorio Staff
Posts: 13171
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.15.37] Crash related to copying game objects

Post by Rseding91 »

Thanks for the report. We don't support copying the meta table on a Factorio game reference. Doing so will result in a crash (or worse). At the moment I can't think of a simple solution that wouldn't have a performance overhead so for now I'm going to say "don't do that" :)
If you want to get ahold of me I'm almost always on Discord.

blueblue
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Tue Apr 11, 2017 7:39 pm
Contact:

Re: [0.15.37] Crash related to copying game objects

Post by blueblue »

I expected something like this, that's okay =)

Is there a simple way to distinguish between game references and normal tables so that I can amend my copy function to give me an error?
unique_2 on discord and mod portal

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [0.15.37] Crash related to copying game objects

Post by Nexela »

Code: Select all

if type(val) == "table" and val.__self then --factorio object (unless of course you set __self on your tables in which case)
type(val.__self) evaluates to "userdata"

Rseding91
Factorio Staff
Factorio Staff
Posts: 13171
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.15.37] Crash related to copying game objects

Post by Rseding91 »

Nexela wrote:

Code: Select all

if type(val) == "table" and val.__self then --factorio object (unless of course you set __self on your tables)
If you do that (set __self) then you get zero support and I'll tell everyone to avoid that mod like the plague :P
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Minor issues”