How big is your Blocks array? It is a two dimensional array right? I am guessing Map[cx, cy] + 1 is greater or equal to the maximum. Remember arrays are zero based, they don't start at 1.