diff options
Diffstat (limited to 'src/StardewModdingAPI/Framework/SGame.cs')
-rw-r--r-- | src/StardewModdingAPI/Framework/SGame.cs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs index 61493e87..fe7d3aa3 100644 --- a/src/StardewModdingAPI/Framework/SGame.cs +++ b/src/StardewModdingAPI/Framework/SGame.cs @@ -200,6 +200,13 @@ namespace StardewModdingAPI.Framework /// <param name="gameTime">A snapshot of the game timing state.</param> protected override void Update(GameTime gameTime) { + // SMAPI exiting, stop processing game updates + if (this.Monitor.IsExiting) + { + this.Monitor.Log("SMAPI shutting down: aborting update.", LogLevel.Trace); + return; + } + // While a background new-day task is in progress, the game skips its own update logic // and defers to the XNA Update method. Running mod code in parallel to the background // update is risky, because data changes can conflict (e.g. collection changed during @@ -216,6 +223,16 @@ namespace StardewModdingAPI.Framework return; } + // While the game is writing to the save file in the background, mods can unexpectedly + // fail since they don't have exclusive access to resources (e.g. collection changed + // during enumeration errors). To avoid problems, events are not invoked while a save + // is in progress. + if (Context.IsSaving) + { + base.Update(gameTime); + return; + } + // raise game loaded if (this.FirstUpdate) { @@ -235,7 +252,6 @@ namespace StardewModdingAPI.Framework catch (Exception ex) { this.Monitor.Log($"An error occured in the base update loop: {ex.GetLogSummary()}", LogLevel.Error); - Console.ReadKey(); } // raise update events @@ -281,6 +297,7 @@ namespace StardewModdingAPI.Framework [SuppressMessage("ReSharper", "RedundantTypeArgumentsOfMethod", Justification = "copied from game code as-is")] protected override void Draw(GameTime gameTime) { + Context.IsInDrawLoop = true; try { if (Game1.debugMode) @@ -932,6 +949,7 @@ namespace StardewModdingAPI.Framework { this.Monitor.Log($"An error occured in the overridden draw loop: {ex.GetLogSummary()}", LogLevel.Error); } + Context.IsInDrawLoop = false; } /**** @@ -1075,7 +1093,7 @@ namespace StardewModdingAPI.Framework } // save loaded event - if (Constants.IsSaveLoaded && !SaveGame.IsProcessing/*still loading save*/ && this.AfterLoadTimer >= 0) + if (Context.IsSaveLoaded && !SaveGame.IsProcessing/*still loading save*/ && this.AfterLoadTimer >= 0) { if (this.AfterLoadTimer == 0) { |