I’m trying to do this in a vector composed of Vec3f:
for (size_t i = 0; i < (mPoints.size() - 10) ; i++) {
glVertex3f(mPoints[i]);
}
But I always get a run time error EXC_BAD_ACCESS … if instead of size() I use an int I get the same error. If instead I simply use size() without the substraction, it works fine…
What’s going on?
It sounds like you are possibly running into a problem where the vector has less than 10 elements in it. So when you subtract 10 from an unsigned value it’s possible for the implementation to wrap around and give you a very large number (basically max – 10). Hence you try and iterate past the bounds of the vector.
Try the following instead