XNA 4.0 - What happens when the window is minimized?

Posted by Conrad Clark on Stack Overflow See other posts from Stack Overflow or by Conrad Clark
Published on 2010-12-30T16:36:19Z Indexed on 2010/12/30 18:54 UTC
Read the original article Hit count: 299

Filed under:
|
|
|

Hello. I'm learning F#, and decided to try making simple XNA games for windows using F# (pure enthusiasm) , and got a window with some images showing up.

Here's the code:

(*Methods*)     
member self.DrawSprites() = 
    _spriteBatch.Begin()
    for i = 0 to _list.Length-1 do
        let spentity = _list.List.ElementAt(i)
        _spriteBatch.Draw(spentity.ImageTexture,new Rectangle(100,100,(int)spentity.Width,(int)spentity.Height),Color.White)      
    _spriteBatch.End()

(*Overriding*)   
override self.Initialize() =
    ChangeGraphicsProfile()                              
    _graphicsDevice <- _graphics.GraphicsDevice
    _list.AddSprite(0,"NagatoYuki",992.0,990.0)
    base.Initialize() 

override self.LoadContent() =         
    _spriteBatch <- new SpriteBatch(_graphicsDevice)
    base.LoadContent()

override self.Draw(gameTime : GameTime) =
    base.Draw(gameTime)
    _graphics.GraphicsDevice.Clear(Color.CornflowerBlue)
    self.DrawSprites()

And the AddSprite Method:

   member self.AddSprite(ID : int,imageTexture : string , width : float, height : float) = 
      let texture = content.Load<Texture2D>(imageTexture)
      list <- list @ [new SpriteEntity(ID,list.Length, texture,Vector2.Zero,width,height)]

The _list object has a ContentManager, here's the constructor:

   type SpriteList(_content : ContentManager byref) =
      let mutable content = _content
      let mutable list = []

But I can't minimize the window, since when it regains its focus, i get this error:

ObjectDisposedException

Cannot access a disposed object.
Object name: 'GraphicsDevice'.

What is happening?

© Stack Overflow or respective owner

Related posts about F#

Related posts about XNA