diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-05-03 11:36:36 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-05-03 11:36:36 -0400 |
commit | 3ed16a8ea67cf847d08d463deef969a3edf99b2e (patch) | |
tree | 10f538ac8772db8127532c7d8f924667fa8fc1be | |
parent | e6d5883224863f3bf436b50179eadf1d686387da (diff) | |
download | SMAPI-3ed16a8ea67cf847d08d463deef969a3edf99b2e.tar.gz SMAPI-3ed16a8ea67cf847d08d463deef969a3edf99b2e.tar.bz2 SMAPI-3ed16a8ea67cf847d08d463deef969a3edf99b2e.zip |
recover game after draw errors to prevent crash
-rw-r--r-- | release-notes.md | 1 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/SGame.cs | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/release-notes.md b/release-notes.md index bf9367e5..5d646276 100644 --- a/release-notes.md +++ b/release-notes.md @@ -14,6 +14,7 @@ For mod developers: See [log](https://github.com/Pathoschild/SMAPI/compare/1.11...1.12). For players: +* SMAPI now recovers the game from mod draw errors to prevent a game crash. * The installer now lets you choose the install path if you have multiple copies of the game, instead of using the first path found. * Fixed an issue where mods on Linux/Mac stopped working after the game saves. diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs index fe7d3aa3..3a82963d 100644 --- a/src/StardewModdingAPI/Framework/SGame.cs +++ b/src/StardewModdingAPI/Framework/SGame.cs @@ -947,7 +947,28 @@ namespace StardewModdingAPI.Framework } catch (Exception ex) { + // log error this.Monitor.Log($"An error occured in the overridden draw loop: {ex.GetLogSummary()}", LogLevel.Error); + + // fix sprite batch + try + { + bool isSpriteBatchOpen = +#if SMAPI_FOR_WINDOWS + SGame.Reflection.GetPrivateValue<bool>(Game1.spriteBatch, "inBeginEndPair"); +#else + SGame.Reflection.GetPrivateValue<bool>(Game1.spriteBatch, "_beginCalled"); +#endif + if (isSpriteBatchOpen) + { + this.Monitor.Log("Recovering sprite batch from error...", LogLevel.Trace); + Game1.spriteBatch.End(); + } + } + catch (Exception innerEx) + { + this.Monitor.Log($"Could not recover sprite batch state: {innerEx.GetLogSummary()}", LogLevel.Error); + } } Context.IsInDrawLoop = false; } |