From 2421fa3fa10b15ebf7bbe2e1893311c27a33b6fd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 6 Jul 2018 19:37:52 -0400 Subject: run new-day task synchronously This avoids issues when mod events are called asynchronously (like IAssetLoaders loading PNG tilesheets on season change while the game is drawing). --- src/SMAPI/Framework/SGame.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 240e9a97..d3865316 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -5,6 +5,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Threading; +using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; @@ -223,7 +224,7 @@ namespace StardewModdingAPI.Framework return; } - // Run loaders synchronously to avoid issues due to mod events triggering + // Run async tasks synchronously to avoid issues due to mod events triggering // concurrently with game code. if (Game1.currentLoader != null) { @@ -233,6 +234,12 @@ namespace StardewModdingAPI.Framework Game1.currentLoader = null; this.Monitor.Log("Game loader done.", LogLevel.Trace); } + if (Game1._newDayTask?.Status == TaskStatus.Created) + { + this.Monitor.Log("New day task synchronising...", LogLevel.Trace); + Game1._newDayTask.RunSynchronously(); + this.Monitor.Log("New day task done.", LogLevel.Trace); + } // While a background task is in progress, the game may make changes to the game // state while mods are running their code. This is risky, because data changes can -- cgit