diff --git a/NewHorizons/Utility/NewHorizonBody.cs b/NewHorizons/Utility/NewHorizonBody.cs index 8eff0b9a..f178e50e 100644 --- a/NewHorizons/Utility/NewHorizonBody.cs +++ b/NewHorizons/Utility/NewHorizonBody.cs @@ -25,12 +25,19 @@ namespace NewHorizons.Utility #region Cache public void LoadCache() { - if (RelativePath != null) Cache = new Cache(RelativePath+".nhcache"); + if (RelativePath == null) + { + Logger.LogWarning("Cannot load cache! RelativePath is null!"); + return; + } + + var pathWithoutExtension = RelativePath.Substring(0, RelativePath.LastIndexOf('.')); + Cache = new Cache(pathWithoutExtension+".nhcache"); } public void UnloadCache(bool writeBeforeUnload=false) { - if (writeBeforeUnload) Cache.WriteToFile(); + if (writeBeforeUnload) Cache?.WriteToFile(); Cache = null; // garbage collection will take care of it }