for (std::vector<PhysicsObject*>::iterator it = CurrentBoxes.begin(); it != CurrentBoxes.end();/*it++*/)
{
(*it)->CalculatePhysicsOrientation();
(*it)->DrawMe();
glm::vec3* CurrentBoxPosition = (*it)->GetCurrentPosition();
if (CurrentBoxPosition->y < -750.0f) {
it = CurrentBoxes.erase(it);
// erase returns the iterator following the removed element.
// that is the element we want to look at next
}
else ++it; // ***else added ***
// current element was not erased, so move to the next one
}
An iterator pointing to the new location of the element that followed the last element erased by the function call. This is the container end if the operation erased the last element in the sequence.
Lets say that the sequence is ABCD.
Point is at B.
If you erase B, the point will be at C. If you don't, then point is still at B.
Now you advance point.
If you did erase B, the next iteration looks at D.
In other words, you want to look at C after the B, don't you? You should move to C either by erase or by ++.