Beware the rounding error (or “Avoiding Out of Range errors”)
Monday, October 26th, 2009When iterating through an array that was generated by some built-in function (such as getVector()), check to make sure you’re rounding the input first. If you get an “out of range” error but your code is fucking perfect, then it’s probably because the rectangle used as input by getVector is skipping a row of pixels because the x,y of said rectangle is being rounded UP. For example, 12.51 becomes 13 but since the rectangle is limited by certain dimensions it simply (stupidly, moronically, fucking ridiculously) truncates the dimensions by one row or column. So when it turns the pixel data into a 1D array it’s missing a whole chunk of data which causes your pre-computed (with the correct dimensions) array length to be too high… hence the iterator will hit a number outside the array’s range.
Judging by the number of results Google returns, this is a pretty fringe case (that or I’m exceptionally stupid… hush). Regardless, it’s a problem that has been plaguing me for the past few months. If it weren’t for my genius programmery brother I would have never found it either. But thanks to him I’m now savvy to what’s termed as “rounding errors”. They even sound evil.
Here’s an example with code…
Click to see details »






I’ve been working on a couple game concepts and want to prototype a few more before committing to one to build out. I’ve been hacking the hell out of