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