开发者

XNA SpriteBatch.End() ObjectDisposedException

开发者 https://www.devze.com 2023-03-31 08:40 出处:网络
I am having some issues with a thrown exception.Below is the draw method from the XNA loop. protected override void Draw(GameTime gameTime)

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 t开发者_C百科he 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消