XNA Texture2D Dispose()+ ObjectDisposedException [英] XNA Texture2D Dispose() + ObjectDisposedException

查看:106
本文介绍了XNA Texture2D Dispose()+ ObjectDisposedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我对XNA框架非常陌生.我正在XNA中为Windows Phone 7编写示例应用程序.

目前我正面临一个问题.

在示例中,我正在加载Texture2D并将其放置在下一行中,然后将其分配为null.再次,我将相同的图像加载到相同的成员变量.但是在平局中我得到了ObjectDisposedException.

如果我删除了dispose调用,它将不会产生任何异常.

请帮我解决这个问题.

样本:

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);
}

推荐答案

然后,我认为Content.Load正在缓存纹理.

要验证这一点:

1)在处理断点之前,先放置断点.
2)将对象ID应用于监视面板中的对象.
3)在再次加载返回"后的行上,查看其是否具有相同的对象ID.

沿着这些思路,应该可以清除...
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...


这篇关于XNA Texture2D Dispose()+ ObjectDisposedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆