我有一个绘制和旋转立方体的类.每次我旋转立方体时,我都会使用多维数据集的新值重新加载缓冲区.
public void LoadBuffer(GraphicsDevice graphicsDevice)
{
buffer = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, triangles * 3, BufferUsage.None);
buffer.SetData<VertexPositionNormalTexture>(verts);
graphicsDevice.SetVertexBuffer(buffer);
}
public void Draw(GraphicsDevice graphicsDevice)
{
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, triangles);
}
Run Code Online (Sandbox Code Playgroud)
然后在Game.Draw中调用Cube.Draw方法
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Target, Color.White, 1f, 0);
basicEffect.Parameters["WorldViewProj"].SetValue(world * view * projection);
EffectPass pass = basicEffect.CurrentTechnique.Passes[0];
if (pass != null)
{
pass.Apply();
cube1.LoadBuffer(GraphicsDevice);
cube1.Draw(GraphicsDevice);
cube2.LoadBuffer(GraphicsDevice);
cube2.Draw(GraphicsDevice);
cube3.LoadBuffer(GraphicsDevice);
cube3.Draw(GraphicsDevice);
}
base.Draw(gameTime);
}
Run Code Online (Sandbox Code Playgroud)
几分钟左右后,我得到一个OutOfMemory Exception就行了:
buffer.SetData<VertexPositionNormalTexture>(verts);
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么会发生这种情况以及我能做些什么来解决它.
所以我想将我的PC游戏转换为在Xbox 360上运行.它在PC上运行得非常好,配备Intel Core 2 Quad @ 2.40Ghz和Radeon 4850 512MB.
我把它移植到Xbox上,然后关于导入列表,有一些关于导入列表的不变性和继承问题,所以我只使用名为.Cast <>()的LINQ方法.
如果这个方法需要很大的开销,请告诉我,因为我无法在360上部署Performance Analysis,原因很可能是因为它在360上播放.
然后又出现了另一个问题,这是一个很好的System.OutOfMemoryException.我的天空盒纹理是4096x4096,所以将它们减半就消除了这个错误.奇怪的是,它们只有3MB x 6,所以不应该使用512MB的那么多.
因此,当所有这些问题都被清除时,每2秒引入一个漂亮的1帧.然后它在游戏1分钟后崩溃,"Code 4"无论那意味着什么.
它就像一个powerpoint.以下是来自PC游戏玩法的一些性能分析图像.他们还不错.
CPU:http://i.imgur.com/JYx7Z.png 内存:http://i.imgur.com/C29KN.png 72%= 150MB请注意.
我希望这里有人在这个问题上有一些经验.坦率地说,我全都是耳朵.