Error on Grid.cs

Aug 25, 2008 at 3:00 AM
Edited Aug 25, 2008 at 3:04 AM
Hi,
sometimes I'm having an error during the execution of the game I'm developing.

It's on Grid.cs, in this function:

public bool Intersect(ref Vector2 vector, out Feature feature) {
            //TODO: Keep and eye out for floating point accuracy issues here. Possibly some
            //VERY intermittent errors exist?
            if (aabb.Contains(ref vector)) {
                int x = (int)Math.Floor((vector.X - aabb.Min.X) * gridCellSizeInv);
                int y = (int)Math.Floor((vector.Y - aabb.Min.Y) * gridCellSizeInv);
               

                float xPercent = (vector.X - (gridCellSize * x + aabb.Min.X)) * gridCellSizeInv;
                float yPercent = (vector.Y - (gridCellSize * y + aabb.Min.Y)) * gridCellSizeInv;

                float bottomLeft = nodes[x, y];
                float bottomRight = nodes[x + 1, y];
                float topLeft = nodes[x, y + 1];
                float topRight = nodes[x + 1, y + 1];

the error occurs in the bold line.

The output says "Index was outside the bounds of the array". The nodes dimension on the moment is [11,11], x is 10 and y is 3.

Any idea of why this error is happening? (or why x = 10 when the nodes dimension is 11, 11)

thanks!