From 93459a5e37b26cc8d742878dd993543c43f70694 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 4 Jan 2020 22:08:01 -0500 Subject: fix new asset invalidation code not correctly handling interceptors which both load and edit --- .../Framework/Content/AssetInterceptorChange.cs | 6 ++++-- src/SMAPI/Framework/SGame.cs | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/Content/AssetInterceptorChange.cs b/src/SMAPI/Framework/Content/AssetInterceptorChange.cs index 498afe36..037d9f89 100644 --- a/src/SMAPI/Framework/Content/AssetInterceptorChange.cs +++ b/src/SMAPI/Framework/Content/AssetInterceptorChange.cs @@ -64,7 +64,8 @@ namespace StardewModdingAPI.Framework.Content { try { - return editor.CanEdit(asset); + if (editor.CanEdit(asset)) + return true; } catch (Exception ex) { @@ -77,7 +78,8 @@ namespace StardewModdingAPI.Framework.Content { try { - return loader.CanLoad(asset); + if (loader.CanLoad(asset)) + return true; } catch (Exception ex) { diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index e2b22ba7..d6c3b836 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -18,6 +18,7 @@ using StardewModdingAPI.Framework.Events; using StardewModdingAPI.Framework.Input; using StardewModdingAPI.Framework.Networking; using StardewModdingAPI.Framework.Reflection; +using StardewModdingAPI.Framework.StateTracking.Comparers; using StardewModdingAPI.Framework.StateTracking.Snapshots; using StardewModdingAPI.Framework.Utilities; using StardewModdingAPI.Toolkit.Serialization; @@ -427,17 +428,24 @@ namespace StardewModdingAPI.Framework return; } - /********* ** Reload assets when interceptors are added/removed *********/ if (this.ReloadAssetInterceptorsQueue.Any()) { - this.Monitor.Log("Invalidating cached assets for new editors & loaders...", LogLevel.Trace); + // get unique interceptors + AssetInterceptorChange[] interceptors = this.ReloadAssetInterceptorsQueue + .GroupBy(p => p.Instance, new ObjectReferenceComparer()) + .Select(p => p.First()) + .ToArray(); + this.ReloadAssetInterceptorsQueue.Clear(); + + // log summary + this.Monitor.Log("Invalidating cached assets for new editors & loaders..."); this.Monitor.Log( - "changed: " + " changed: " + string.Join(", ", - this.ReloadAssetInterceptorsQueue + interceptors .GroupBy(p => p.Mod) .OrderBy(p => p.Key.DisplayName) .Select(modGroup => @@ -448,8 +456,8 @@ namespace StardewModdingAPI.Framework ) ); - this.ContentCore.InvalidateCache(asset => this.ReloadAssetInterceptorsQueue.Any(p => p.CanIntercept(asset))); - this.ReloadAssetInterceptorsQueue.Clear(); + // reload affected assets + this.ContentCore.InvalidateCache(asset => interceptors.Any(p => p.CanIntercept(asset))); } /********* -- cgit