Skip to content

Commit

Permalink
Prevents NullReferenceException when saving the cache to pause the lo…
Browse files Browse the repository at this point in the history
…ading
  • Loading branch information
sarbian committed Sep 5, 2015
1 parent 868eb44 commit 4e5e45c
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions moduleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,14 +1006,38 @@ private void CreateCache()
node.AddNode(config.config);
}

cache.Save(cachePath);
try
{
cache.Save(cachePath);
return;
}
catch (NullReferenceException e)
{
log("NullReferenceException while saving the cache\n" + e.ToString());
}
catch (Exception e)
{
log("Exception while saving the cache\n" + e.ToString());
}

try
{
log("An error occured while creating the cache. Deleting the cache files to avoid keeping a bad cache");
if (File.Exists(cachePath))
File.Delete(cachePath);
if (File.Exists(shaPath))
File.Delete(shaPath);
}
catch (Exception e)
{
log("Exception while deleting the cache\n" + e.ToString());
}
}

private void SaveModdedTechTree()
{
UrlDir.UrlConfig[] configs = GameDatabase.Instance.GetConfigs("TechTree");


if (configs.Length == 0)
{
log("No TechTree node found. No custom TechTree will be saved");
Expand Down Expand Up @@ -1099,6 +1123,12 @@ private void CheckNeeds(List<string> excludePaths)
continue;
}

if (mod.config.name == null)
{
log("Error - Node in file " + currentMod.parent.url + " subnode: " + currentMod.type +
" has config.name == null");
}

if (currentMod.type.Contains(":NEEDS["))
{
mod.parent.configs.Remove(currentMod);
Expand Down Expand Up @@ -1171,6 +1201,13 @@ private void CheckNeeds(ConfigNode subMod, string url, List<string> path)
{
ConfigNode node = subMod.nodes[i];
string nodeName = node.name;

if (nodeName == null)
{
log("Error - Node in file " + url + " subnode: " + string.Join("/", path.ToArray()) +
" has config.name == null");
}

try
{
if (CheckNeeds(ref nodeName))
Expand Down

0 comments on commit 4e5e45c

Please sign in to comment.