I currently develop a mod generating dynamic structures like outposts or walls automatically and have some problems storing the data persistent. I found that the metatable is not stored in the savegame so i have to reset it in onload.
I am not quite shure what i have done, but in some way i must have created a structure in the glob variable that causes a stack overflow error when it gets loaded.
When the game autosaves, onload is called (is this by purpose?) and my own method (recursive tree walk) causes stack overflow and loading the game after restart crashes the game (also with stack overflow)
My guess is that there is a circular reference in the structure (a table that contains a table containing the outer one) and your loadLuaObjects Method is not able to handle this (mine reactivateMeta neither) but i have no clue why there should be.
I added the logfile zipped as neither .log nor .txt are allowed extensions. I also added current version of my mod so you can reproduce it.
[0.11.19] loading crash: modding experiments
[0.11.19] loading crash: modding experiments
- Attachments
-
- AutomaticExpansion_0.1.0.zip
- (121.74 KiB) Downloaded 178 times
-
- factorio-previous.zip
- (4.09 KiB) Downloaded 179 times
-
- _autosave3.zip
- (2.54 MiB) Downloaded 159 times
Re: [0.11.19] loading crash: modding experiments
The use of metatables is not supported officially.Kevin94 wrote: I found that the metatable is not stored in the savegame so i have to reset it in onload.
Yes, the onload is called in autosave on purpose. The reason is that save is destructive operation. Basically it replaces the content of the objects with our internal identifiers and then the data structures are saved as they are using serpent library. This keeps the correct referencing among the objects. When the game is loaded the serpent data are loaded and then based on their internals the linking to the game objects (i.e. Entity, Player) is done.Kevin94 wrote:When the game autosaves, onload is called (is this by purpose?)
If there is a circular reference then stack overflow could happen indeed. However that is not really a problem of the saving / loading mechanism but of the data having a circular reference. Hope the above description helps.Kevin94 wrote: My guess is that there is a circular reference in the structure (a table that contains a table containing the outer one) and your loadLuaObjects Method is not able to handle this (mine reactivateMeta neither) but i have no clue why there should be.
At the moment we are starting to focus on 0.12 and imho this looks like it is a problem of your mod creating a recursive structure. So I will put the issue to minor issues for now. If you find more (the mod forums is a good place to discuss this imho) please let us know.
Re: [0.11.19] loading crash: modding experiments
In case some future mod developer wil stumble upon this, I found the circular reference and it was on purpose:
Is anywhere documented which parts of lua are not supported and maybe even why they aren't?
I hope by "not supported officially" you didn't meant "we will disable them at some point". I already have another way in mind how to restore the metatables and imho metatables are the nicest way implementing OOP in lua.
Code: Select all
local Polygon = {}
Polygon.__index = Polygon --circular reference
function createPolygon()
local self = setmetatable({}, Polygon)
self.metatable = Polygon -- intended to restore metatable after onload but includes circular reference
-- ...
return self
end
I hope by "not supported officially" you didn't meant "we will disable them at some point". I already have another way in mind how to restore the metatables and imho metatables are the nicest way implementing OOP in lua.