diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-05-07 02:50:36 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-05-07 02:50:36 -0400 |
commit | 8963793bf854bee368b5cd08a3e0eb410ee8e1a9 (patch) | |
tree | c2a1460804673a455738c624e524c697b5697c39 | |
parent | 0e304e4d51857e3c7dc9cd18141176e44934755c (diff) | |
download | SMAPI-8963793bf854bee368b5cd08a3e0eb410ee8e1a9.tar.gz SMAPI-8963793bf854bee368b5cd08a3e0eb410ee8e1a9.tar.bz2 SMAPI-8963793bf854bee368b5cd08a3e0eb410ee8e1a9.zip |
exit game after many consecutive unrecoverable draw errors (#283)
-rw-r--r-- | src/StardewModdingAPI/Framework/SGame.cs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs index dbc257e1..f8226529 100644 --- a/src/StardewModdingAPI/Framework/SGame.cs +++ b/src/StardewModdingAPI/Framework/SGame.cs @@ -34,6 +34,12 @@ namespace StardewModdingAPI.Framework /// <remarks>Skipping a few frames ensures the game finishes initialising the world before mods try to change it.</remarks> private int AfterLoadTimer = 5; + /// <summary>The maximum number of consecutive attempts SMAPI should make to recover from a draw error.</summary> + private readonly int MaxFailedDraws = 120; // roughly two seconds + + /// <summary>The number of consecutive failed draws.</summary> + private int FailedDraws = 0; + /// <summary>Whether the player has loaded a save and the world has finished initialising.</summary> private bool IsWorldReady => this.AfterLoadTimer < 0; @@ -944,9 +950,20 @@ namespace StardewModdingAPI.Framework } } } + + // reset failed draw count + this.FailedDraws = 0; } catch (Exception ex) { + // exit if irrecoverable + if (this.FailedDraws >= this.MaxFailedDraws) + { + this.Monitor.ExitGameImmediately("the game crashed when drawing, and SMAPI was unable to recover the game."); + return; + } + this.FailedDraws++; + // log error this.Monitor.Log($"An error occured in the overridden draw loop: {ex.GetLogSummary()}", LogLevel.Error); |