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

Suggestions that have been added to the game.

Moderator: ickputzdirwech

User avatar
mentlerd
Manual Inserter
Manual Inserter
Posts: 4
Joined: Fri Jun 09, 2017 10:15 am
Contact:

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

Post 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.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14300
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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
If you want to get ahold of me I'm almost always on Discord.
User avatar
mentlerd
Manual Inserter
Manual Inserter
Posts: 4
Joined: Fri Jun 09, 2017 10:15 am
Contact:

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

Post 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?
Rseding91
Factorio Staff
Factorio Staff
Posts: 14300
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post by Rseding91 »

We don't use __serialize in the serpent library. We just call serpent.dump() on the table.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Implemented Suggestions”