Click here to Skip to main content
11,645,889 members (66,729 online)
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
Anshh747
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)

  Print Answers RSS
0 jyo.net 814
1 OriginalGriff 648
2 Sergey Alexandrovich Kryukov 478
3 CPallini 414
4 Afzaal Ahmad Zeeshan 378
0 OriginalGriff 1,143
1 jyo.net 994
2 Sergey Alexandrovich Kryukov 808
3 Afzaal Ahmad Zeeshan 702
4 DamithSL 691


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100