Skip to main content
added 561 characters in body
Source Link
monty
  • 384
  • 1
  • 2
  • 11
if (a < 0 || a > 15) // now with this never gets out of range
            Debug.Log("A out of range: " + a);

if (b < 0 || b > 15) // now with this never gets out of range
            Debug.Log("B out of range: " + b);

submap is bool[15,15] (according to comments)

then that should be

if (b < 0 || b >= 15)

or

if (b < 0 || b > 14)

index 15 would be already outside of bounds (size 15, indizes 0 - 14)

Since you couldn't trace your bug with the current if statement this leads to the conclusion your invalid index causing the exception is 15 and not a negative index.


Since part one didn't find the problem the next chance is to not check the submap[a][b] array but the world.WalkableMap[] array.

Just do the same as with a b.

int c = (int)CurrentWalkableTile.x + i;
int d = (int)CurrentWalkableTile.y + j;

if (c < 0 || c >= world.WalkableMap.length) Debug.Log("C out of range: " + c); 

if (d < 0 || d >= world.WalkableMap[0].length) Debug.Log("d out of range: " + d);

Because you are using two arrays but so far you haven't excluded one causing the IndexOutOfBoundsException.

if (a < 0 || a > 15) // now with this never gets out of range
            Debug.Log("A out of range: " + a);

if (b < 0 || b > 15) // now with this never gets out of range
            Debug.Log("B out of range: " + b);

submap is bool[15,15] (according to comments)

then that should be

if (b < 0 || b >= 15)

or

if (b < 0 || b > 14)

index 15 would be already outside of bounds (size 15, indizes 0 - 14)

Since you couldn't trace your bug with the current if statement this leads to the conclusion your invalid index causing the exception is 15 and not a negative index.

if (a < 0 || a > 15) // now with this never gets out of range
            Debug.Log("A out of range: " + a);

if (b < 0 || b > 15) // now with this never gets out of range
            Debug.Log("B out of range: " + b);

submap is bool[15,15] (according to comments)

then that should be

if (b < 0 || b >= 15)

or

if (b < 0 || b > 14)

index 15 would be already outside of bounds (size 15, indizes 0 - 14)

Since you couldn't trace your bug with the current if statement this leads to the conclusion your invalid index causing the exception is 15 and not a negative index.


Since part one didn't find the problem the next chance is to not check the submap[a][b] array but the world.WalkableMap[] array.

Just do the same as with a b.

int c = (int)CurrentWalkableTile.x + i;
int d = (int)CurrentWalkableTile.y + j;

if (c < 0 || c >= world.WalkableMap.length) Debug.Log("C out of range: " + c); 

if (d < 0 || d >= world.WalkableMap[0].length) Debug.Log("d out of range: " + d);

Because you are using two arrays but so far you haven't excluded one causing the IndexOutOfBoundsException.

added 25 characters in body
Source Link
monty
  • 384
  • 1
  • 2
  • 11
if (a < 0 || a > 15) // now with this never gets out of range
            Debug.Log("A out of range: " + a);

if (b < 0 || b > 15) // now with this never gets out of range
            Debug.Log("B out of range: " + b);

submap is bool[15,15] (according to comments)

then that should be

if (b < 0 || b >= 15)

or

if (b < 0 || b > 14)

index 15 would be already outside of bounds (size 15, indizes 0 - 14)

Since you couldn't trace your bug with the current if statement this leads to the conclusion your invalid index causing the exception is 15 and not a negative index.

if (a < 0 || a > 15) // now with this never gets out of range
            Debug.Log("A out of range: " + a);

if (b < 0 || b > 15) // now with this never gets out of range
            Debug.Log("B out of range: " + b);

submap is bool[15,15] (according to comments)

then that should be

if (b < 0 || b >= 15)

or

if (b < 0 || b > 14)

index 15 would be already outside of bounds (size 15, indizes 0 - 14)

Since you couldn't trace your bug with the current if statement this leads to the conclusion your invalid index causing the exception is 15.

if (a < 0 || a > 15) // now with this never gets out of range
            Debug.Log("A out of range: " + a);

if (b < 0 || b > 15) // now with this never gets out of range
            Debug.Log("B out of range: " + b);

submap is bool[15,15] (according to comments)

then that should be

if (b < 0 || b >= 15)

or

if (b < 0 || b > 14)

index 15 would be already outside of bounds (size 15, indizes 0 - 14)

Since you couldn't trace your bug with the current if statement this leads to the conclusion your invalid index causing the exception is 15 and not a negative index.

Source Link
monty
  • 384
  • 1
  • 2
  • 11

if (a < 0 || a > 15) // now with this never gets out of range
            Debug.Log("A out of range: " + a);

if (b < 0 || b > 15) // now with this never gets out of range
            Debug.Log("B out of range: " + b);

submap is bool[15,15] (according to comments)

then that should be

if (b < 0 || b >= 15)

or

if (b < 0 || b > 14)

index 15 would be already outside of bounds (size 15, indizes 0 - 14)

Since you couldn't trace your bug with the current if statement this leads to the conclusion your invalid index causing the exception is 15.