My xna game has this "rogue" System.InvalidOperationException which only happens sometimes and seems to be triggered at random or at least something out of my control input wise. After pressing start and loading the first menu screen, (I used the GameStateManagement sample as the base for my game if that helps whatsoever) the game sometimes but not always throws a System.InvalidOperationException at the "in" part of "foreach (GameScreen screen in screens)" Full code for the method:
/// <summary>
/// Tells each screen to draw itself.
/// </summary>
public override void Draw(GameTime gameTime)
{
foreach (GameScreen screen in screens) //exception thrown at the "in" part
{
if (screen.ScreenState == ScreenState.Hidden)
continue;
screen.Draw(gameTime);
}
}
I'm honestly clueless as to what triggers this exception because I'm not doing anything different from when it throws the exception and when it doesn't. I'm not exactly sure if this will help you but this is the exception details
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at GameStateManagement.ScreenManager.Draw(GameTime gameTime)
at Microsoft.Xna.Framework.Game.Draw(GameTime gameTime)
at GameStateManagement.GameStateManagementGame.Draw(GameTime gameTime)
at Microsoft.Xna.Framework.Game.DrawFrame()
at Microsoft.Xna.Framework.Game.Tick()
at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
at Microsoft.Xna.Framework.GameHost.OnIdle()
at Microsoft.Xna.Framework.XboxGameHost.RunOneFrame()
at Microsoft.Xna.Framework.XboxGameHost.Run()
at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
at Microsoft.Xna.Framework.Game.Run()
at GameStateManagement.Program.Main()
} System.Exception {System.InvalidOperationException}
and this is the call stack:
> GameStateManagementSample.exe!GameStateManagement.ScreenManager.Draw(Microsoft.Xna.Framework.GameTime gameTime) Line 338 + 0x33 bytes C#
Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.Draw(Microsoft.Xna.Framework.GameTime gameTime) + 0x4d bytes
GameStateManagementSample.exe!GameStateManagement.GameStateManagementGame.Draw(Microsoft.Xna.Framework.GameTime gameTime) Line 89 + 0x7 bytes C#
Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.DrawFrame() + 0x6a bytes
Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.Tick() + 0x2a9 bytes
Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.HostIdle(object sender, System.EventArgs e) + 0x6 bytes
Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.GameHost.OnIdle() + 0x19 bytes
Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.XboxGameHost.RunOneFrame() + 0xc bytes
Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.XboxGameHost.Run() + 0x1b bytes
Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.RunGame(bool useBlockingRun) + 0x9c bytes
Microsoft.Xna.Framework.Game.dll!Microsoft.Xna.Framework.Game.Run() + 0x7 bytes
GameStateManagementSample.exe!GameStateManagement.Program.Main() Line 108 + 0x6 bytes C#
Thanks! Ivatrix.