diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-04-29 21:46:01 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-04-29 21:46:01 -0400 |
commit | f52edf9e0b267e79f88c492e7d7e34f63744f21c (patch) | |
tree | 1d1d6dbd88aca1e456ac3ceff351a6f611c281f1 /src/StardewModdingAPI | |
parent | ff5d1ef4e4a096405b343de3f6d27715c248de3b (diff) | |
download | SMAPI-f52edf9e0b267e79f88c492e7d7e34f63744f21c.tar.gz SMAPI-f52edf9e0b267e79f88c492e7d7e34f63744f21c.tar.bz2 SMAPI-f52edf9e0b267e79f88c492e7d7e34f63744f21c.zip |
fix mod events triggering during game save in Stardew Valley 1.2
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r-- | src/StardewModdingAPI/Context.cs | 3 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/SGame.cs | 10 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Context.cs b/src/StardewModdingAPI/Context.cs index d737bd58..415b4aac 100644 --- a/src/StardewModdingAPI/Context.cs +++ b/src/StardewModdingAPI/Context.cs @@ -11,6 +11,9 @@ namespace StardewModdingAPI /// <summary>Whether a player save has been loaded.</summary> public static bool IsSaveLoaded => Game1.hasLoadedGame && !string.IsNullOrEmpty(Game1.player.name); + /// <summary>Whether the game is currently writing to the save file.</summary> + public static bool IsSaving => SaveGame.IsProcessing; + /// <summary>Whether the game is currently running the draw loop.</summary> public static bool IsInDrawLoop { get; set; } } diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs index 7e04c391..fe7d3aa3 100644 --- a/src/StardewModdingAPI/Framework/SGame.cs +++ b/src/StardewModdingAPI/Framework/SGame.cs @@ -223,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) { |