From 7167cd2253ae9320e34eff5f2c6d6dd9ad0d0eef Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 24 Aug 2017 22:17:42 -0400 Subject: simplify & fix asset disposal (#352) --- src/StardewModdingAPI/Framework/SContentManager.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/StardewModdingAPI/Framework') 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 /// Matches the asset keys to invalidate. /// Whether to dispose invalidated assets. This should only be true when they're being invalidated as part of a dispose, to avoid crashing the game. /// Returns whether any cache entries were invalidated. - public bool InvalidateCache(Func predicate, bool dispose = true) + public bool InvalidateCache(Func predicate, bool dispose = false) { // find matching asset keys HashSet purgeCacheKeys = new HashSet(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 keys = new HashSet( - 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); } -- cgit