OldStuff
[0.9.4] util.Table.DeepCopy() Corrupts entitys
[0.9.4] util.Table.DeepCopy() Corrupts entitys
As nobody posted in this thread I'm re-purposing it, it turns out using table.deepcopy() on a table containing entity's causes the game to corrupt. I was able to get around the problem by writing my own table copy function that doesn't change meta tables. Using table.deepcopy() on entity's causes the game to crash.
Re: [0.9.4] util.Table.DeepCopy() Corrupts entitys
Thanks for the report. The problem here is that the "factorio" lua objects (i.e. lua entity, lua technology) need to correspond to the C++ object in the backend. Factorio lua objects cannot be "raw-copied" (table copy of attributes). So the result of using deepcopy was there were two distinct tables that corresponded to one instance in the backend. When the original table (the one we copied from) is garbage collected (GC is explicitly triggered every 300ticks or so) then the object is deleted and the copy becomes invalid (it tries to call functions on deleted C++ object).
For 0.9.5 I have changed the definition of deepcopy as follows:
This way the factorio objects will be treated as references within the deepcopy. This actually makes better sense because the entity in the game "cannot be copies", you can only make 2 distinct references.
For 0.9.5 I have changed the definition of deepcopy as follows:
Code: Select all
if type(object) ~= "table" then
return object
-- presence of __self parameter means this is a factorio object
elseif object.__self then
return object
elseif ...