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

亡梦爱人 提交于 2019-12-24 04:09:08

问题


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...)


回答1:


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.



来源:https://stackoverflow.com/questions/6181175/xna-4-0-app-closes-suddenly-when-it-hits-a-method-without-throwing-any-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!