我有一个绘制和旋转立方体的类。每次我旋转立方体我重新加载与立方体的新值的缓冲区。OutOfMemory绘制立方体时出现异常
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);
}
然后调用Cube.Draw方法Game.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);
}
几分钟后,还是让我得到就行了内存溢出异常:
buffer.SetData<VertexPositionNormalTexture>(verts);
有人能请解释为什么会发生这种情况,以及我能做些什么来解决这个问题。
喜,@harryovers,你有没有找到解决办法,带着这种“BUG”,我觉得选择XNA太难过了。 – 2013-01-06 14:38:37
@DuSijun我确实得到了这个工作,但它是2。5年前,所以我真的不记得很多关于它的细节抱歉。 – harryovers 2013-01-23 19:07:22