hi, i have a class that draws and rotates a cube. every time i rotate the cube i reload the buffer with the new values for the cube.
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);
}
then call the Cube.Draw method in 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);
}
after a couple of minutes or so i get an OutOfMemory Exception on the line:
buffer.SetData<VertexPositionNormalTexture>(verts);
could somebody please explain why this is happening and what i can do to solve it.