Cube chunk via list ToArray()

Posted by Christian Frantz on Game Development See other posts from Game Development or by Christian Frantz
Published on 2013-06-29T21:35:00Z Indexed on 2013/06/29 22:29 UTC
Read the original article Hit count: 264

Filed under:
|

I've created a list of vertices that I call for each cube made in my array "cubes". When each cube is create, SetUpVertices is called which is a method that stores the 8 vertices of my cube. At the end of my list creation, I create a vertex buffer, and set the data of the list that contains vertices of all 25 cubes to that vertex buffer, effectively creating a "chunk" of cubes. The problem is that Invalid Operation Exception "The array is not the correct size for the amount of data requested." at the line vertices.ToArray(). I don't have an array for this, as the amount of cubes will be changing and arrays aren't dynamic. What could be the cause of this?

     for (int x = 0; x < 5; x++)
        {
            for (int z = 0; z < 5; z++)
            {
                SetUpVertices();
                cubes.Add(new Cube(device, new Vector3(x, map[x, z], z), color));
            }
        }

        vertexBuffer = new VertexBuffer(device, typeof(VertexPositionColor), 8, BufferUsage.WriteOnly);
        vertexBuffer.SetData<VertexPositionColor>(vertices.ToArray());

© Game Development or respective owner

Related posts about XNA

Related posts about c#