
-----------------------------------
Tubs
Sat Sep 13, 2008 3:11 pm

C# arrayoutofbounds
-----------------------------------
I am trying to initialize an array of colours to handle collision detection in an artillery game. 

The logic of this code is:
- initialize a 1D array and a 2D to the size of the target map texture, in this case 
private void ProcessTerrain()
        {
             
            Map.tempMap = new Color[terrainTexture.Width * terrainTexture.Height];
            Map.terrainMap = new Color[terrainTexture.Width, terrainTexture.Height];
            Map.scaledMap = new Color[1920, 1080];
            String error;

            terrainTexture.GetData(Map.tempMap);
            

            // Translate 1D tempMap array into 2D terrainMap array
            
            for (int i = 0; i < terrainTexture.Width; i++)
            {
                for (int j = 0; j < terrainTexture.Height; j++) {
                    Map.terrainMap[i, j] = Map.tempMap[terrainTexture.Width*j + i];                
                }
            }

            Map.bg = Map.terrainMap[0, 0];

            //Scale to twice the size

            for (int i = 0; i < terrainTexture.Height; i++)
            {
                for (int j = 0; j < terrainTexture.Width; j++)
                {
                        Map.scaledMap[2 * i, 2 * j] = Map.terrainMap[i, j];
                        Map.scaledMap[2 * i + 1, 2 * j] = Map.terrainMap[i, j];
                        Map.scaledMap[2 * i, 2 * j + 1] = Map.terrainMap[i, j];
                        Map.scaledMap[2 * i + 1, 2 * j + 1] = Map.terrainMap[i, j];
                    
                }
            }
        }


-----------------------------------
Stove
Sun Sep 21, 2008 8:47 pm

Re: C# arrayoutofbounds
-----------------------------------
Is the exception thrown when it first enters the 2nd nested loop? or after it starts iterating through it?
