In my experience, usually this happens when one of the variables being passed is off by one. (A common mistake is misordering elements in an array so that they are off by one from their actual values, eg: position 0 is the first element, NOT position 1. At this point passing a value that is off by one, because you assume 1 is the beginning makes things break).