我有一個繪製和旋轉立方體的類。每次我旋轉立方體我重新加載與立方體的新值的緩衝區。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