Content Patcher

Content Patcher

378k Downloads

[Lookup Anything] crash if used during Stardew Valley Fair

Pathoschild opened this issue ยท 2 comments

commented

If you look something up during the Stardew Valley Fair (and possibly some other events), the game crashes with the following error:

System.InvalidOperationException: Nesting more than one SpriteBatch.Begin when using a SpriteBatch with SpriteSortMode.Immediate is not allowed.
   at Microsoft.Xna.Framework.Graphics.SpriteBatch.Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect, Matrix transformMatrix)
   at Microsoft.Xna.Framework.Graphics.SpriteBatch.Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState)
   at Pathoschild.LookupAnything.Components.LookupMenu.draw(SpriteBatch spriteBatch)
   at StardewModdingAPI.Inheritance.SGame.Draw(GameTime gameTime) in Z:\Projects\SMAPI\src\StardewModdingAPI\Inheritance\SGame.cs:line 1302

This happens because Lookup Anything uses a separate sprite batch for the pagination clipping, which always works except if the game uses SpriteSortMode.Immediate (which it apparently does during certain events).

Reported via Nexus mod bug and Nexus private message.

commented

Revamped error handling in 79dd1a8, so errors won't crash the game in some cases anymore. Fixing the actual error is harder; we may need to rethink how pagination works.

commented

As of 1.6 via 825ee45, the mod detects when the game's rendering mode is incompatible and disables lookups (with a log message).

I decided on that approach for a few reasons:

  • This is only known to happen during the Stardew Valley Fair.
  • The only thing you can look up during the Stardew Valley Fair is yourself (since the NPCs aren't really there).
  • Nested sprite batches are fundamental to the way the mod draws its UI, and the alternative approaches would greatly complicate the logic for little benefit (given the previous points).