Handle texture-disposed errors while drawing
Pathoschild opened this issue · 1 comments
Stardew Valley 1.2.29 has a common issue where a texture becomes disposed while it's in use, causing the screen to go black and this message to be thrown endlessly:
[18:36:36 ERROR SMAPI] An error occured in the overridden draw loop: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Texture2D'.
at Microsoft.Xna.Framework.Helpers.CheckDisposed(Object obj, IntPtr pComPtr)
at Microsoft.Xna.Framework.Graphics.TextureCollection.set_Item(Int32 index, Texture value)
at Microsoft.Xna.Framework.Graphics.SpriteBatch.RenderBatch(Texture2D texture, SpriteInfo[] sprites, Int32 offset, Int32 count)
at Microsoft.Xna.Framework.Graphics.SpriteBatch.Flush()
at Microsoft.Xna.Framework.Graphics.SpriteBatch.End()
at StardewModdingAPI.Framework.SGame.Draw(GameTime gameTime) in D:\source\_Stardew\SMAPI\src\StardewModdingAPI\Framework\SGame.cs:line 647
Look into whether it's possible to recover (e.g. by removing or replacing the texture), else end the game.
Done in develop
for the upcoming release.
SMAPI now exits the game when it detects either of two cases:
- calling
Game1.spriteBatch.End()
during recovery crashed, which means the sprite batch is corrupted; - or recovery succeeds, but there are sixty consecutive draw crashes (≈ one second).
Although SMAPI can't fix the draw crash plaguing Stardew Valley 1.2.29, I forwarded all the details I found to the developers.