diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-08-24 22:17:42 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-08-24 22:17:42 -0400 |
commit | 7167cd2253ae9320e34eff5f2c6d6dd9ad0d0eef (patch) | |
tree | 67860861175f2ef8763acb03281e735ce5c1f919 | |
parent | 5171829ecc8acd8dc0e3292bd3c2c7893a148c8f (diff) | |
download | SMAPI-7167cd2253ae9320e34eff5f2c6d6dd9ad0d0eef.tar.gz SMAPI-7167cd2253ae9320e34eff5f2c6d6dd9ad0d0eef.tar.bz2 SMAPI-7167cd2253ae9320e34eff5f2c6d6dd9ad0d0eef.zip |
simplify & fix asset disposal (#352)
-rw-r--r-- | src/StardewModdingAPI/Framework/SContentManager.cs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/StardewModdingAPI/Framework/SContentManager.cs b/src/StardewModdingAPI/Framework/SContentManager.cs index 4c4eee58..9553e79f 100644 --- a/src/StardewModdingAPI/Framework/SContentManager.cs +++ b/src/StardewModdingAPI/Framework/SContentManager.cs @@ -246,7 +246,7 @@ namespace StardewModdingAPI.Framework /// <param name="predicate">Matches the asset keys to invalidate.</param> /// <param name="dispose">Whether to dispose invalidated assets. This should only be <c>true</c> when they're being invalidated as part of a dispose, to avoid crashing the game.</param> /// <returns>Returns whether any cache entries were invalidated.</returns> - public bool InvalidateCache(Func<string, Type, bool> predicate, bool dispose = true) + public bool InvalidateCache(Func<string, Type, bool> predicate, bool dispose = false) { // find matching asset keys HashSet<string> purgeCacheKeys = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase); @@ -294,12 +294,10 @@ namespace StardewModdingAPI.Framework internal void DisposeFor(ContentManagerShim shim) { this.Monitor.Log($"Content manager '{shim.Name}' disposed, disposing assets that aren't needed by any other asset loader.", LogLevel.Trace); - HashSet<string> keys = new HashSet<string>( - from entry in this.AssetLoaders - where entry.Value.Count == 1 && entry.Value.First() == shim - select entry.Key - ); - this.InvalidateCache((key, type) => keys.Contains(key)); + + foreach (var entry in this.AssetLoaders) + entry.Value.Remove(shim); + this.InvalidateCache((key, type) => !this.AssetLoaders[key].Any(), dispose: true); } |