summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-06-24 17:00:39 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-06-24 17:00:39 -0400
commitca9efad7a7949ca87f3ccf7ec4d01332d1fad84b (patch)
tree801d6e51548093496b2d7bb3964ecfd65d20612a /src/SMAPI/Framework
parent525ca7c9c99272c5aff557545c285f4307526589 (diff)
downloadSMAPI-ca9efad7a7949ca87f3ccf7ec4d01332d1fad84b.tar.gz
SMAPI-ca9efad7a7949ca87f3ccf7ec4d01332d1fad84b.tar.bz2
SMAPI-ca9efad7a7949ca87f3ccf7ec4d01332d1fad84b.zip
avoid cancellation token for tracking exit state
This apparently causes noticeable lag for a minority of players.
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/SCore.cs27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index cc332225..16c168a0 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -66,8 +66,8 @@ namespace StardewModdingAPI.Framework
/****
** Low-level components
****/
- /// <summary>Tracks whether the game should exit immediately and any pending initialization should be cancelled.</summary>
- private readonly CancellationTokenSource CancellationToken = new();
+ /// <summary>Whether the game should exit immediately and any pending initialization should be cancelled.</summary>
+ private bool IsExiting;
/// <summary>Manages the SMAPI console window and log file.</summary>
private readonly LogManager LogManager;
@@ -272,16 +272,6 @@ namespace StardewModdingAPI.Framework
new TitleMenuPatcher(this.OnLoadStageChanged)
);
- // add exit handler
- this.CancellationToken.Token.Register(() =>
- {
- if (this.IsGameRunning)
- {
- this.LogManager.WriteCrashLog();
- this.Game.Exit();
- }
- });
-
// set window titles
this.UpdateWindowTitles();
}
@@ -358,8 +348,8 @@ namespace StardewModdingAPI.Framework
// dispose core components
this.IsGameRunning = false;
+ this.IsExiting = true;
this.ContentCore?.Dispose();
- this.CancellationToken.Dispose();
this.Game?.Dispose();
this.LogManager.Dispose(); // dispose last to allow for any last-second log messages
@@ -374,7 +364,7 @@ namespace StardewModdingAPI.Framework
/// <summary>Initialize mods before the first game asset is loaded. At this point the core content managers are loaded (so mods can load their own assets), but the game is mostly uninitialized.</summary>
private void InitializeBeforeFirstAssetLoaded()
{
- if (this.CancellationToken.IsCancellationRequested)
+ if (this.IsExiting)
{
this.Monitor.Log("SMAPI shutting down: aborting initialization.", LogLevel.Warn);
return;
@@ -436,7 +426,7 @@ namespace StardewModdingAPI.Framework
commandManager: this.CommandManager,
reloadTranslations: this.ReloadTranslations,
handleInput: input => this.RawCommandQueue.Add(input),
- continueWhile: () => this.IsGameRunning && !this.CancellationToken.IsCancellationRequested
+ continueWhile: () => this.IsGameRunning && !this.IsExiting
)
).Start();
}
@@ -479,7 +469,7 @@ namespace StardewModdingAPI.Framework
** Special cases
*********/
// Abort if SMAPI is exiting.
- if (this.CancellationToken.IsCancellationRequested)
+ if (this.IsExiting)
{
this.Monitor.Log("SMAPI shutting down: aborting update.");
return;
@@ -2233,7 +2223,10 @@ namespace StardewModdingAPI.Framework
private void ExitGameImmediately(string message)
{
this.Monitor.LogFatal(message);
- this.CancellationToken.Cancel();
+ this.LogManager.WriteCrashLog();
+
+ this.IsExiting = true;
+ this.Game.Exit();
}
/// <summary>Get the screen ID that should be logged to distinguish between players in split-screen mode, if any.</summary>