diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/StardewModdingAPI/Framework/SGame.cs | 21 |
1 files changed, 21 insertions, 0 deletions
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; } |