XNA SpriteBatch.End() ObjectDisposeException
我遇到一些抛出异常的问题。下面是 XNA 循环中的绘制方法。
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.White);
checkInitialization(); // Makes sure that the graphics loader has been initialized
spriteBatch.Begin();
GameRunner.CurrentGame.GraphicsSystem.Draw(this.spriteBatch);
spriteBatch.End(); // Exception is thrown here
base.Draw(gameTime);
}
这是图形系统的绘制方法。
public void Draw(SpriteBatch spriteBatch)
{
foreach (GraphicsComponent component in this.components)
{
component.Draw(spriteBatch, this.texture);
}
}
图形组件存储在List<>中。在图形系统中。我认为问题的一部分可能是我跨项目工作。上面的顶部循环位于 XNA 项目中。第二种绘制方法是在我构建的游戏库中。最后,component.draw() 方法的实际实现是在第三个项目中,该项目特定于我正在开发的当前游戏。图形系统中的纹理字段是在图形系统构建时从 Content.Load 函数初始化的。
我尝试了几种不同的方法。我将 spritebatch.begin 和 spritebatch.end 移至图形系统中,但这仍然导致异常。当图形系统中的组件列表为空时,不会出现该异常。
我不确定当范围从一个项目移动到另一个项目时加载的纹理是否超出范围,但我认为情况不应该如此。我也在一个有效的单个项目中进行了相同类型的设置,但是我将其重构为多个以便在其他地方使用一些代码。我不会在正在消失的纹理上的任何地方调用“dispose”,所以我什至不确定要开始寻找。
如果不清楚,请告诉我,我会尽力详细说明。
I am having some issues with a thrown exception. Below is the draw method from the XNA loop.
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.White);
checkInitialization(); // Makes sure that the graphics loader has been initialized
spriteBatch.Begin();
GameRunner.CurrentGame.GraphicsSystem.Draw(this.spriteBatch);
spriteBatch.End(); // Exception is thrown here
base.Draw(gameTime);
}
And here is the draw method from the graphics system.
public void Draw(SpriteBatch spriteBatch)
{
foreach (GraphicsComponent component in this.components)
{
component.Draw(spriteBatch, this.texture);
}
}
The graphics components are stored in a List<> in the graphicsSystem. I am thinking that part of the issue may be that I a working across projects. The Top loop above is in an XNA project. The second draw method is in a game library I constructed. And finally the actual implementation of the component.draw() method is in a third project that is specific to the current game I am working on. the texture field in the graphics system is initalized from the Content.Load function upon construction of the graphics system.
I have tried a couple different things. I moved the spritebatch.begin and spritebatch.end into the graphics system, which still resulted in the exception. The exception does not appear when the components list in the graphics system is empty.
I am not sure if the loaded texture is going out of scope when the scope moves from one project to another, but I don't think this should be the case. I have also had the same sort of setup in a single project that worked, however I was refactoring into multiple to make some use of some of the code elsewhere. I am not calling dispose anywhere on the texture that is disappearing, so I am not even really sure to begin hunting.
If this isn't clear, let me know and I will try to elaborate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我需要知道你如何管理内容......
我想如果你不手动处理纹理,你就会在某个地方处理内容管理器。
当您使用 game.Content.Load(asset) 加载资源时,内容管理器会保留已加载资源的列表,并且内容管理器负责在调用 game.Cntent.Dispose() 时释放它们。
I'd need to know how do you manage content...
I suppose if you are not disposing manually the textures, you are disposing the Content Manager in some place.
When you load assets with game.Content.Load(asset), the content manager keeps a list of the resources loaded, and the content manager is responsible to free them when game.Cntent.Dispose() is called.