From 2b1b3b19a507876e106a444c93b4c33aca35c353 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 4 Apr 2021 11:40:08 -0400 Subject: improve error-handling during asset propagation --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/SMAPI/Metadata/CoreAssetPropagator.cs') diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 83ed52ad..3146ceaf 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using Microsoft.Xna.Framework.Graphics; using Netcode; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.ContentManagers; using StardewModdingAPI.Framework.Reflection; using StardewModdingAPI.Toolkit.Utilities; @@ -36,15 +37,18 @@ namespace StardewModdingAPI.Metadata /// An internal content manager used only for asset propagation. See remarks on . private readonly GameContentManagerForAssetPropagation DisposableContentManager; + /// Writes messages to the console. + private readonly IMonitor Monitor; + + /// Simplifies access to private game code. + private readonly Reflector Reflection; + /// Whether to enable more aggressive memory optimizations. private readonly bool AggressiveMemoryOptimizations; /// Normalizes an asset key to match the cache key and assert that it's valid. private readonly Func AssertAndNormalizeAssetName; - /// Simplifies access to private game code. - private readonly Reflector Reflection; - /// Optimized bucket categories for batch reloading assets. private enum AssetBucket { @@ -65,12 +69,14 @@ namespace StardewModdingAPI.Metadata /// Initialize the core asset data. /// The main content manager through which to reload assets. /// An internal content manager used only for asset propagation. + /// Writes messages to the console. /// Simplifies access to private code. /// Whether to enable more aggressive memory optimizations. - public CoreAssetPropagator(LocalizedContentManager mainContent, GameContentManagerForAssetPropagation disposableContent, Reflector reflection, bool aggressiveMemoryOptimizations) + public CoreAssetPropagator(LocalizedContentManager mainContent, GameContentManagerForAssetPropagation disposableContent, IMonitor monitor, Reflector reflection, bool aggressiveMemoryOptimizations) { this.MainContentManager = mainContent; this.DisposableContentManager = disposableContent; + this.Monitor = monitor; this.Reflection = reflection; this.AggressiveMemoryOptimizations = aggressiveMemoryOptimizations; @@ -116,7 +122,17 @@ namespace StardewModdingAPI.Metadata default: foreach (var entry in bucket) { - bool changed = this.PropagateOther(entry.Key, entry.Value, ignoreWorld, out bool curChangedMapWarps); + bool changed = false; + bool curChangedMapWarps = false; + try + { + changed = this.PropagateOther(entry.Key, entry.Value, ignoreWorld, out curChangedMapWarps); + } + catch (Exception ex) + { + this.Monitor.Log($"An error occurred while propagating asset changes. Error details:\n{ex.GetLogSummary()}", LogLevel.Error); + } + propagatedAssets[entry.Key] = changed; updatedNpcWarps = updatedNpcWarps || curChangedMapWarps; } -- cgit