summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-07-03 14:49:29 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-07-03 14:49:29 -0400
commit96da7c1cbc19e079e06fe8c7c857ffe86c0d9848 (patch)
tree1a48d810a1e7174c73b5a28066716d22eb613616 /src
parent72c9e956e7b7012a503af0c77434105785a84ef4 (diff)
downloadSMAPI-96da7c1cbc19e079e06fe8c7c857ffe86c0d9848.tar.gz
SMAPI-96da7c1cbc19e079e06fe8c7c857ffe86c0d9848.tar.bz2
SMAPI-96da7c1cbc19e079e06fe8c7c857ffe86c0d9848.zip
fix crash in new content manager when returning to title (#255)
Diffstat (limited to 'src')
-rw-r--r--src/StardewModdingAPI/Framework/SContentManager.cs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Framework/SContentManager.cs b/src/StardewModdingAPI/Framework/SContentManager.cs
index ebf1c8a5..42c3b0e6 100644
--- a/src/StardewModdingAPI/Framework/SContentManager.cs
+++ b/src/StardewModdingAPI/Framework/SContentManager.cs
@@ -349,5 +349,23 @@ namespace StardewModdingAPI.Framework
yield return new KeyValuePair<IModMetadata, T>(metadata, interceptor);
}
}
+
+ /// <summary>Dispose all game resources.</summary>
+ /// <param name="disposing">Whether the content manager is disposing (rather than finalising).</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (!disposing)
+ return;
+
+ // Clear cache & reload all assets. While that may seem perverse during disposal, it's
+ // necessary due to limitations in the way SMAPI currently intercepts content assets.
+ //
+ // The game uses multiple content managers while SMAPI needs one and only one. The game
+ // only disposes some of its content managers when returning to title, which means SMAPI
+ // can't know which assets are meant to be disposed. Here we remove current assets from
+ // the cache, but don't dispose them to avoid crashing any code that still references
+ // them. The garbage collector will eventually clean up any unused assets.
+ this.Reset();
+ }
}
}