I am trying to create multiple BoundingBoxes on a Model by following this tutorial:


However, I keep getting this error: Requested range extends past the end of the array. on this line:

part.VertexBuffer.GetData(part.VertexOffset * stride, vertexData, 0, part.NumVertices, stride);

I can't figure out why it is giving me that. I load my model and try to create the boxes like this:

Model model = this.Content.Load<Model>("Cube");
MeshModel box = new MeshModel(model);

Instead of passing a String path of the model, I just pass the Model itself (I changed the constructor to accept Model model).

Any help would be appreciated!

Here's what the debugger says (the vertexStride and VertexBuffer has 24 which is the same size as the vertexData so it should be ok):

enter image description here


2 Answers 2


In the tutorial you are using, vertexData is an array of a number of VertexPositionNormalTexture. But if your cube is made from a type of Vertex that is different (say VertexPositionColor for instance), then you have to adjust vertexData accordingly.

VertexPositionColor[] vertexData = new VertexPositionColor[part.NumVertices];

If you expand the Vertex Declaration line on your debugger output, we can see what type of Vertex Blender gave you and Xna probably has a Vertex that fits it.


That looks like an ArgumentOutOfRangeException message. If you're using XNA's GetData method, that can occur because:

  • The vertex stride is larger than the vertex buffer, or
  • The vertex stride is too small for the type of data requested.

It seems likely that you're vertexData array is too small to hold the requested amount of data, but you should attach a debugger and verify. It's also possible the calculations you're doing for the other parameters do not match the actual data you have available in the buffer.

  • \$\begingroup\$ I attached the debugger output in the OP. The size seems fine, unless I'm misunderstanding. My model is the default cube from Blender (when you first open it). If I make the vertexData array bigger then it just fills it with 0 values for the VertexPositionNormalTexture after the 24th index. \$\endgroup\$
    – syy
    Aug 12, 2016 at 8:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .