正如标题所说,我有一个 XNA 应用程序,当它点击一个应用程序时突然关闭,但没有显示任何错误,所以我什至不知道如何开始调试它。代码非常简单——我只是在玩 XNA 并尝试渲染一个简单的三角形——所以我无法想象它为什么会停止。正在运行的代码是
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);
}
是 Draw() 函数搞砸了。当我删除 DrawUserPrimitives 行时,它运行良好(虽然什么都不显示......)
最佳答案
我假设“ScreenManager”是一个继承自“DrawableGameComponent”的类,而您正在从那里访问图形设备?确保在 Game 类的构造函数中的某处初始化 GraphicsDeviceManager(this)。
我认为是您的 ScreenManager 静态抓取的“GraphicsDevice”可能未正确初始化。
关于c# - XNA 4.0 应用程序在遇到方法时突然关闭而没有抛出任何异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6181175/