Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Windows Mobile XNA3.0
Hi,
 
I am very new to XNA framework. I am writing a sample application in XNA for windows phone 7.
 
presently I am facing a problem.
 
In the sample, I am loading a Texture2D and disposing it in the next line and then assigning it to null. Again I am loading the same image to the same member variable. But in the draw I get ObjectDisposedException.
 
If I remove the dispose call it will not give any exception.
 
Please help me to solve this.
 
Sample:
Texture2D texture = null;
 protected override void LoadContent()
 {
      texture = Content.Load<Texture2D>("Back");
      texture .Dispose();
      texture = null;
 
      texture = Content.Load<Texture2D>("Back");
}
protected override void Draw(GameTime gameTime)
{
      GraphicsDevice.Clear(Color.CornflowerBlue);
 
      spriteBatch.Begin();
      spriteBatch.Draw(texture , new Vector2(0, 0), Color.White);
 
      spriteBatch.End();
 
       base.Draw(gameTime);
}
Posted 20-Jul-10 2:30am
Anshh746
Edited 20-Jul-10 2:39am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I would assume then that Content.Load is caching off the textures.
 
To verify this:
 
1) Put a breakpoint right before you dispose it.
2) Apply an object ID to the object in the watch panel.
3) On the line after you load "Back" again, see if its the same object ID.
 
Something along those lines should clear that up...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 20 Jul 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid