From 8963793bf854bee368b5cd08a3e0eb410ee8e1a9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 7 May 2017 02:50:36 -0400 Subject: exit game after many consecutive unrecoverable draw errors (#283) --- src/StardewModdingAPI/Framework/SGame.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') 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 /// Skipping a few frames ensures the game finishes initialising the world before mods try to change it. private int AfterLoadTimer = 5; + /// The maximum number of consecutive attempts SMAPI should make to recover from a draw error. + private readonly int MaxFailedDraws = 120; // roughly two seconds + + /// The number of consecutive failed draws. + private int FailedDraws = 0; + /// Whether the player has loaded a save and the world has finished initialising. 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); -- cgit