From c7f12c967b4f8060e90d04ab793207a24a3c040a Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Mon, 30 Jan 2023 22:52:43 -0500 Subject: [PATCH] cache now gets written to file when body building is successful --- NewHorizons/Handlers/PlanetCreationHandler.cs | 2 +- NewHorizons/Utility/NewHorizonBody.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index db5d7430..6c36fdec 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -273,7 +273,7 @@ namespace NewHorizons.Handlers Logger.LogError($"Error in event handler for OnPlanetLoaded on body {body.Config.name}: {e}"); } - body.UnloadCache(); + body.UnloadCache(true); return true; } diff --git a/NewHorizons/Utility/NewHorizonBody.cs b/NewHorizons/Utility/NewHorizonBody.cs index 074ccf71..8eff0b9a 100644 --- a/NewHorizons/Utility/NewHorizonBody.cs +++ b/NewHorizons/Utility/NewHorizonBody.cs @@ -28,8 +28,10 @@ namespace NewHorizons.Utility if (RelativePath != null) Cache = new Cache(RelativePath+".nhcache"); } - public void UnloadCache() + public void UnloadCache(bool writeBeforeUnload=false) { + if (writeBeforeUnload) Cache.WriteToFile(); + Cache = null; // garbage collection will take care of it } #endregion Cache