Further details of the exception: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
When reading the exception, I understand what it's trying to tell me. What I don't understand is -why- it's coming up. Here is the snippet of relevant code:
//the model contains more than one mesh, so each
//one must be accounted for in the final sphere
List<BoundingSphere> spheres = new List<BoundingSphere>();
int index = 0;
//cycle through the meshes
foreach (ModelMesh mesh in this.model.Meshes)
{
//and grab its bounding sphere
spheres[index++] = mesh.BoundingSphere; //<- this is the line that throws the exception
} //end foreach
While debugging, I can see in the table provided by Visual Studio that my model.Meshes.Count is 5, and that at the current iteration, index is 1. Index is less than the size of my collection, and it is non-negative.
What's throwing the exception? I've tried searching for similar examples, but haven't found anything to quite answer my question yet.
Thanks in advance.