- Home /
IndexOutOfRangeException only on iOS! Android / PC is ok!!
Hello everybody!
I have a problem that is driving me crazy! I'm generating a three-dimensional array, and when I run inside the Unity, or Android, everything works perfectly.
But when I run on iOS, happens IndexOutOfRangeException error when creating the array!
Anyone have any idea why?
void GenerateWorldData () {
WorldData = new byte[Width, Height, Depth];
_perlingNoise = new PerlingNoise(Seed, 15);
Debug.Log(WorldData.GetLength(0) + "," + WorldData.GetLength(1) + "," + WorldData.GetLength(2));
for (int x = 0; x < Width; x++)
{
for (int y = 0; y < Height; y++)
{
for (int z = 0; z < Depth; z++)
{
if (y >= 24 && y <= 24 + 2)
{
WorldData[x, y, z] = (byte)VoxelType.Occlusion;
}
else
{
int stone = _perlingNoise.GetPerlingNoise(x, z, 18) + 15;
int dirt = stone + _perlingNoise.GetPerlingNoise(x, z, 8) + 10;
int grass = dirt + 1;
if (y <= stone)
{
WorldData[x, y, z] = (byte)VoxelType.Stone;
}
else if(y <= dirt)
{
WorldData[x, y, z] = (byte)VoxelType.Dirt;
}
else if(y <= grass)
{
WorldData[x, y, z] = (byte)VoxelType.Grass;
}
else
{
WorldData[x, y, z] = (byte)VoxelType.Air;
}
}
}
}
Debug.Log(x);
}
Debug.Log("Finished");
}
And this is the error that appears on the xCode console:
IndexOutOfRangeException: Array index is out of range.
at (wrapper managed-to-managed) object:ElementAddr (object,int,int,int)
at World.GenerateWorldData () [0x00000] in <filename unknown>:0
at World.CreateWorld () [0x00000] in <filename unknown>:0
at World.Awake () [0x00000] in <filename unknown>:0
(Filename: Line: -1)
Hmm strange indeed. Have you tried it with a smaller array, maybe your apple device is not up to the task?
Answer by hav_ngs_ru · Jan 22, 2015 at 12:23 PM
like a rain-dance... have you tried to use integer instead of byte?
but the better way is the deep debugging. Try to detect what x,y,z values causes exception? log values and see what conbinations was the last. at the same time detect the exact line where it happens. then it will be more clearly (or less darkly :))
The X, Y and Z go at last "10", than the error appears... =( I will try change the byte type to int...
Thats work! Its the BYTE type... I change to INT and works!!!
I dont know why, but iOS build wont support uint, bytes, ufloat types...