This project is read-only.

Exception raised when dragging/resizing window

Oct 13, 2011 at 5:35 AM

I've been getting various exceptions when resizing, dragging or hiding/obscuring a game window. There are at least 3 different exceptions: null reference, cannot access a disposed object and target invocation unhandled by user code. It's not entirely reproducible, but dragging a window from one monitor to the other and back will usually trigger it. It seems to be related to disposing and recreating the GraphicsDevice. Here is two examples.

Is this is a known problem?

System.ObjectDisposedException was unhandled by user code
  Message=Cannot access a disposed object.
Object name: 'GraphicsDevice'.
  Source=Microsoft.Xna.Framework
  ObjectName=GraphicsDevice
  StackTrace:
       at Microsoft.Xna.Framework.Helpers.CheckDisposed(Object obj, IntPtr pComPtr)
       at Microsoft.Xna.Framework.Graphics.DepthStencilState.Apply(GraphicsDevice device)
       at Microsoft.Xna.Framework.Graphics.GraphicsDevice.set_DepthStencilState(DepthStencilState value)
       at Microsoft.Xna.Framework.Graphics.SpriteBatch.SetRenderState()
       at Microsoft.Xna.Framework.Graphics.SpriteBatch.End()
       at Nine.Components.FrameRate.Draw(TimeSpan elapsedTime) in D:\MyDocs\Active\vs10-xna4\Samples\svn\Framework\Nine.Graphics\Components\FrameRate.cs:line 118
       at Nine.Components.GameComponentAdapter.Draw(GameTime gameTime) in D:\MyDocs\Active\vs10-xna4\Samples\svn\Framework\Nine\Components\GameComponentCollectionExtensions.cs:line 75
       at Microsoft.Xna.Framework.Game.Draw(GameTime gameTime)
       at SceneTest2.SceneTestGame.Draw(GameTime gameTime) in D:\MyDocs\Active\vs10-xna4\NineEngine\SceneTest\SceneTest2\SceneTest2\SceneTestGame.cs:line 153
       at Microsoft.Xna.Framework.Game.DrawFrame()
       at Microsoft.Xna.Framework.Game.Paint(Object sender, EventArgs e)
       at Microsoft.Xna.Framework.GameWindow.OnPaint()
       at Microsoft.Xna.Framework.WindowsGameWindow.mainForm_Paint(Object sender, PaintEventArgs e)
  InnerException: 

System.Reflection.TargetInvocationException was unhandled by user code
  Message=Exception has been thrown by the target of an invocation.
  Source=mscorlib
  StackTrace:
       at System.RuntimeMethodHandle._InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct& signature, RuntimeType declaringType)
       at System.RuntimeMethodHandle.InvokeConstructor(IRuntimeMethodInfo method, Object[] args, SignatureStruct signature, RuntimeType declaringType)
       at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
       at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
       at System.Activator.CreateInstance(Type type, Object[] args)
       at Nine.Graphics.GraphicsResources`1.GetInstance(GraphicsDevice graphics) in D:\MyDocs\Active\vs10-xna4\Samples\svn\Framework\Nine.Graphics\GraphicsResources.cs:line 45
       at Nine.Components.FrameRate.Draw(TimeSpan elapsedTime) in D:\MyDocs\Active\vs10-xna4\Samples\svn\Framework\Nine.Graphics\Components\FrameRate.cs:line 114
       at Nine.Components.GameComponentAdapter.Draw(GameTime gameTime) in D:\MyDocs\Active\vs10-xna4\Samples\svn\Framework\Nine\Components\GameComponentCollectionExtensions.cs:line 75
       at Microsoft.Xna.Framework.Game.Draw(GameTime gameTime)
       at SceneTest2.SceneTestGame.Draw(GameTime gameTime) in D:\MyDocs\Active\vs10-xna4\NineEngine\SceneTest\SceneTest2\SceneTest2\SceneTestGame.cs:line 153
       at Microsoft.Xna.Framework.Game.DrawFrame()
       at Microsoft.Xna.Framework.Game.Paint(Object sender, EventArgs e)
       at Microsoft.Xna.Framework.GameWindow.OnPaint()
       at Microsoft.Xna.Framework.WindowsGameWindow.mainForm_Paint(Object sender, PaintEventArgs e)
  InnerException: System.NullReferenceException
       Message=Object reference not set to an instance of an object.
       Source=Microsoft.Xna.Framework.Graphics
       StackTrace:
            at Microsoft.Xna.Framework.Graphics.Effect.CreateEffectFromCode(GraphicsDevice graphicsDevice, Byte[] effectCode)
            at Microsoft.Xna.Framework.Graphics.Effect..ctor(GraphicsDevice graphicsDevice, Byte[] effectCode)
            at Microsoft.Xna.Framework.Graphics.SpriteBatch..ctor(GraphicsDevice graphicsDevice)
       InnerException: