XNA 4.0应用程序突然关闭当它击中的方法没有抛出任何异常 [英] XNA 4.0 app closes suddenly when it hits a method without throwing any exceptions
问题描述
正如标题所说,我有一个XNA应用程序,突然关闭,当它击中的应用程序,但不显示任何错误,所以我没有线索如何甚至开始调试它做。代码很简单 - 我只是用XNA玩,并试图呈现一个简单的三角形 - 所以我不能想象为什么它停止。该公司正在运行的代码是
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);
}
和它的Draw()函数的螺丝它。当我删除DrawUserPrimitives线运行良好(虽然什么都不显示...)
and it's the Draw() function that screws it up. When I remove the DrawUserPrimitives line it runs fine (although show nothing...)
推荐答案
我将假设屏幕管理'是继承了一个类的DrawableGameComponent',你是从那里访问图形设备?使你的游戏类你初始化的GraphicsDeviceManager(本)的构造肯定的地方。
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).
我认为这是'GraphicsDevice的你的ScreenManager是抓住了静态可能未正确初始化。
I think it's the 'GraphicsDevice' that your ScreenManager is grabbing statically that might not be initialised properly.
这篇关于XNA 4.0应用程序突然关闭当它击中的方法没有抛出任何异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!