开发者

XNA 4.0 app closes suddenly when it hits a method without throwing any exceptions

As the title says, I have an XNA app that closes suddenly when it hits an app, but doesn't show any errors so I don't have a clue how to even begin to debug it. The code is very simple - I'm just playing with XNA and trying to render a simple triangle - so I can't imagine why it's stopping. The code that's running is

    VertexPositionColor[] vertices;

    public Terrain()
    {
        vertices = new VertexPositionColor[3];
        vertices[0].Position = new Vector3(-0.5f, -0.5f, 0f);
        vertices[0].Color = Color.Red;
        vertices[1].Position = new Vector3(0, 0.5f, 0f);
        vertices[1].Color = Color.Green;
        vertices[2].Position = new Vector3(0.5f, -0.5f, 0f);
        vertices[2].Color = Color.Yellow;
    }

    public void Draw(GameTime gameTime)
    {
        ScreenManager.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
            PrimitiveType.TriangleList,
            vertices,
           开发者_开发百科 0,
            1,
            VertexPositionColor.VertexDeclaration);
    }

and it's the Draw() function that screws it up. When I remove the DrawUserPrimitives line it runs fine (although show nothing...)


I'm going to assume that 'ScreenManager' is a class that inherits off 'DrawableGameComponent' and you are accessing the graphics device from there? Make sure somewhere in the constructor of your Game class you are initialising the GraphicsDeviceManager(this).

I think it's the 'GraphicsDevice' that your ScreenManager is grabbing statically that might not be initialised properly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜