Hi, i'm testing my mod's ability to survive a save -> load transition, and currently it does not, but I don't know why. The logs do not help. What is the issue? It occurs when either one or both of my global simple tables (containing only Factorio classes in them in the form of entity references) contain something. For example with my mod, i can start a clean game, the tables are created but empty except for the Squad table which just has an empty UnitGroup in it, using the player name as a Key in the table.
When I place a droid soldier down, it (the on entity placed event callback function) adds that entity to the Solders global table, and then in an on-tick event adds every soldier in the list to the UnitGroup (in the global Squad table).
I then save the game, and then load the game, as a test. Every time I load a game which has a soldier unit crashes. I haven't tried killing the guy to see if his entity being nil or invalid helps at all.
I attached the mod exactly how it is currently, my save "ROBOTTEST", and the log file.
The important code is in the control.lua file btw, if there is a bug or i'm doing something wrong (or missed something critical like something I MUST do in the on_load event) please help me..
edit: I actually just managed to get it to save and load with a single soldier guy active, but then I spawned the remaining 4 that you start with and then tried the save->load cycle again, and this time it crashed again. Perhaps there is some unknown state that happens often, but I managed to get it in a "correct" state between attempts? maybe before the on_tick event custom code was called (only happens every 20 ticks so maybe I beat it to making the save)?
[0.12.29][Oxyd] Crash when loading save - one mod active
[0.12.29][Oxyd] Crash when loading save - one mod active
- Attachments
-
- factorio-save-load-testing-1-success.log
- managed to do save/load cycle after placing a droid unit down.
- (5.88 KiB) Downloaded 166 times
-
- bug report.zip
- (845.23 KiB) Downloaded 139 times
Re: [0.12.29] Crash when loading save - one mod active
I am making a second post, just for chronological management... I made some minor adjustments in the control.lua for various events but nothing really imporant.
I managed to have multiple droids following me around and save/load cycle worked, but only one or twice, and then bam another crash when attempting the third save/load cycle. Save error code in the log. But the conditions of droid or no droid, or how many droids, is not seemingly the case.
I have attached the current state of my debugging, the mod and the save and the log file.
I managed to have multiple droids following me around and save/load cycle worked, but only one or twice, and then bam another crash when attempting the third save/load cycle. Save error code in the log. But the conditions of droid or no droid, or how many droids, is not seemingly the case.
I have attached the current state of my debugging, the mod and the save and the log file.
- Attachments
-
- bug report 2.zip
- managed to save and load with multiple droids in squad following me around, but second/third try caused a crash now
- (1.08 MiB) Downloaded 146 times
Re: [0.12.29][Oxyd] Crash when loading save - one mod active
The problem is that your droids are in the player force, but you are adding them to unit groups belonging to the enemy force. This apparently confused Factorio enough to corrupt the save. The save corruption is fixed in 0.12.31.
In addition, you will now get an error if you try to .add_member of one force to a unit group of a different force. LuaSurface::create_unit_group optionally takes a force parameter which allows you to specify the force of a unit group. So, everywhere where you create unit groups in your mod, you need to do it like so:
In addition, you will now get an error if you try to .add_member of one force to a unit group of a different force. LuaSurface::create_unit_group optionally takes a force parameter which allows you to specify the force of a unit group. So, everywhere where you create unit groups in your mod, you need to do it like so:
Code: Select all
global.Squads[player.name] = player.surface.create_unit_group({position=player.position, force=player.force})
Re: [0.12.29][Oxyd] Crash when loading save - one mod active
AH thank you so much, I didn't realize the force ownership issue of the unitgroup. This makes a whole bunch of sense now. This maybe explains why the "enemy" force squads were sometimes being disbanded randomly, or controlled by the AI game engine.
When I properly set the force of the unitgroup, do I need to use the force.ai_controllable = true command, or should i keep it as false? Does that that actually mean? The description in the Mod API is ambiguous in terms of if the game engine will attempt to take over the unitgroup, or will normal calls to unitgroup.set_command() be ignore if aI_controllable = false?
I see that by default, "force = enemy" unitgroups have ai_controllable = true, but all other force's unitgroups have ai_controllable = false. Can you clarify if that means they will not obey set_command until this parameter is set to true?
I will fix it later today and get back to you with confirmation.
When I properly set the force of the unitgroup, do I need to use the force.ai_controllable = true command, or should i keep it as false? Does that that actually mean? The description in the Mod API is ambiguous in terms of if the game engine will attempt to take over the unitgroup, or will normal calls to unitgroup.set_command() be ignore if aI_controllable = false?
I see that by default, "force = enemy" unitgroups have ai_controllable = true, but all other force's unitgroups have ai_controllable = false. Can you clarify if that means they will not obey set_command until this parameter is set to true?
I will fix it later today and get back to you with confirmation.
Re: [0.12.29][Oxyd] Crash when loading save - one mod active
confirmed, that change of adding the force of the player to the create unit group function fixed the corrupted save/load issue. Thanks again!
Re: [0.12.29][Oxyd] Crash when loading save - one mod active
ai_controllable enables the expansion mechanic. The game won't take over unit groups that you created by calling create_unit_group and it has no bearing on the commands you give to the groups.kyranzor wrote:When I properly set the force of the unitgroup, do I need to use the force.ai_controllable = true command, or should i keep it as false? Does that that actually mean? The description in the Mod API is ambiguous in terms of if the game engine will attempt to take over the unitgroup, or will normal calls to unitgroup.set_command() be ignore if aI_controllable = false?
Re: [0.12.29][Oxyd] Crash when loading save - one mod active
Thank youOxyd wrote:ai_controllable enables the expansion mechanic. The game won't take over unit groups that you created by calling create_unit_group and it has no bearing on the commands you give to the groups.kyranzor wrote:When I properly set the force of the unitgroup, do I need to use the force.ai_controllable = true command, or should i keep it as false? Does that that actually mean? The description in the Mod API is ambiguous in terms of if the game engine will attempt to take over the unitgroup, or will normal calls to unitgroup.set_command() be ignore if aI_controllable = false?