Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 962601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:32:04+00:00 2026-05-16T01:32:04+00:00

i have a class that draws and rotates a cube. every time i rotate

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:32:04+00:00Added an answer on May 16, 2026 at 1:32 am

    Vertex buffers are unmanaged resources. The garbage collector doesn’t know that they are using a whole bunch of unmanaged memory (and GPU resources) behind the scenes. All it knows about is the tiny little bit of managed memory that each one uses.

    I speak more about unmanaged resources in XNA in my answer to this question.

    You could call Dispose() on each VertexBuffer before you leak it (but after drawing finishes, as it will still be in use!), to release the unmanaged resources. This will avoid the out of memory error, but will still be very slow!

    What you really should be doing is creating the minimum necessary vertex buffers only once. The ideal place to do this is in your LoadContent function (and then Dispose() them in your UnloadContent function). If you have a whole bunch of cubes, all you need is a single vertex buffer that describes a cube, which you reuse every time you draw a cube.

    Obviously you don’t want to draw all your cubes in the same place. This is what the World matrix is for. Each time you draw a cube, set BasicEffect.World to your transformation matrix for that cube and call Apply().

    (The way you are setting WorldViewProj directly is ok too. But using the nice API is, well, nicer.)

    If rotation is what you want, use Matrix.CreateFromYawPitchRoll(yaw, pitch, roll) to create your transformation matrix.

    For more details about this, your problem is similar to another question I have answered.

    (Note that, if the vertices themselves really do change each frame, you should use DrawUserPrimitives. But note that this is still considerably slower than letting the vertex shader on the GPU handle any transformations.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm missing something fundamental here. i have a very simple custom class that draws
I have class that looks like this: class A { public: class variables_map vm
I have a Class that has a private variable with a public setter/getter function:
Currently on a view I have a ImageView and A custom class that draws
I have a class called GraphView that extends UIView that basically draws a small
I have a java application that streams raw data and draws real time plots
I have a class that draws a GUI, using gtk. Clicking a button will
I have a class that draws a rounded rectangle, puts a border around it,
I have a class that accepts a Control and draws generated images to it.
I have found this class that draws circles with different colors. The color of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.