Page 1 of 1

[0.16.51] Cannot load game save with sufficiently complex 'global' saved by mod

Posted: Thu Nov 08, 2018 10:15 pm
by mentlerd
When saving the game, Factorio serializes the 'global' table into script.dat in the savefile, in plain parseable Lua script. If a mod writes a sufficiently complex table structure into its globals variable, the save fails to serialize that table into Lua code that can be loaded by the Lua parser.

In hopes of getting this fixed, I have created a proof-of-concept serializer that solves this issue by serializing objects in two passes, much like current solution, but makes sure the dependencies are never deeper than they must be: https://gist.github.com/mentlerd/114340 ... 5de6594de6

How to reproduce:

Code: Select all

commands.add_command("ruin_my_save", "none", function(ctx)
  local tbl = {}
  
  for i = 1, 256 do
    tbl = {tbl}
  end

  global.HUGE = tbl
end)
Error when loading the save:

Code: Select all

Error while running deserialisation for mod: too many C levels (limit is 200)
While this issue is unlikely to affect many people, one of the mods I am contributing to is playing with the idea to use the 'global' table for expensive to compute indexes, which usually involve long chains of tables containing each other.

Re: [0.16.51] Cannot load game save with sufficiently complex 'global' saved by mod

Posted: Fri Nov 09, 2018 10:53 am
by Rseding91
Nice. If you wanted to attempt to merge your changes into the official serpent library we'd probably end up using it for 0.17. https://github.com/pkulchenko/serpent

Re: [0.16.51] Cannot load game save with sufficiently complex 'global' saved by mod

Posted: Sat Nov 10, 2018 1:55 pm
by mentlerd
Frankly I find serpent a bit too dense, and it takes a very different approach than my solution, integration would result in the worst of both words.

I would be happy to reimplement the same API, specifically the feature set you would like to use. I am guessing the #1 thing is to support __serialize for Factorio objects. Would that be also acceptable? If so could you provide code where you call Serpent?

Re: [0.16.51] Cannot load game save with sufficiently complex 'global' saved by mod

Posted: Sat Nov 10, 2018 2:51 pm
by Rseding91
We don't use __serialize in the serpent library. We just call serpent.dump() on the table.