Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: Windows Mobile XNA3.0
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.
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)
      spriteBatch.Draw(texture , new Vector2(0, 0), Color.White);
Posted 20-Jul-10 2:30am
Edited 20-Jul-10 2:39am

1 solution

Rate this: bad
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...

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