This :
|
IEnumerator autoSaveShip() { |
|
QDebug.Log ("autoSaveShip: start", "QPersistent"); |
|
while (HighLogic.LoadedSceneIsEditor && QSettings.Instance.enableEditorAutoSaveShip) { |
|
QDebug.Log("autoSaveShip: before WaitForSeconds(" + QSettings.Instance.editorTimeToSave + "", "QPersistent"); |
|
yield return new WaitForSeconds (QSettings.Instance.editorTimeToSave); |
|
List<Part> parts = EditorLogic.fetch.ship != null ? EditorLogic.fetch.ship.Parts : new List<Part>(); |
|
|
|
if (parts.Count > 0) |
|
{ |
|
QDebug.Log("autoSaveShip: before saveShip", "QPersistent"); |
|
ShipConstruction.SaveShip(shipFilename); |
|
QDebug.Log("autoSaveShip: after saveShip", "QPersistent"); |
|
} |
|
} |
|
QDebug.Log ("autoSaveShip: end", "QPersistent"); |
|
} |
I'm not sure exactly why, by the call to ShipConstruction.SaveShip() occasionally result in a borked ship save. My guess is that yield return new WaitForSeconds (QSettings.Instance.editorTimeToSave); result in the method being called at a time where the ship / editor isn't a steady state.
Instead of saving the current ship instance, maybe you could get the last backup. Try replacing :
List<Part> parts = EditorLogic.fetch.ship != null ? EditorLogic.fetch.ship.Parts : new List<Part>();
if (parts.Count > 0)
{
QDebug.Log("autoSaveShip: before saveShip", "QPersistent");
ShipConstruction.SaveShip(shipFilename);
QDebug.Log("autoSaveShip: after saveShip", "QPersistent");
}
by
if (ShipConstruction.backups.Count > 0)
{
ShipConstruction.backups[ShipConstruction.backups.Count - 1].Save(shipFilename);
}
Also, instead of using a coroutine, you could subscribe to GameEvents.onEditorSetBackup.
This :
QuickMods/QuickStart/QS_Persistent.cs
Lines 115 to 130 in ccc6923
I'm not sure exactly why, by the call to ShipConstruction.SaveShip() occasionally result in a borked ship save. My guess is that
yield return new WaitForSeconds (QSettings.Instance.editorTimeToSave);result in the method being called at a time where the ship / editor isn't a steady state.Instead of saving the current ship instance, maybe you could get the last backup. Try replacing :
by
Also, instead of using a coroutine, you could subscribe to
GameEvents.onEditorSetBackup.