1

Closed

Arguments out of Bounds Exception

description

When running the SceneManagerTest and the Test projects, I get an Arguments out of Bounds Exception. It is in the following code:
 
try
        {
            IZone zone = new Zone(Game, this);
            zone.Load(zoneElement);
            Zones.Add(zone);
        }
        catch
 
the zone.Load(zoneElement); creates an exception which never loads Zones.Add(zone); This causes an exception when later it tries to get all the zones from Zones list. The list however does not have any items in it causing an exception when this line is run:
 
public IZone ActiveZone
    {
        get { return Zones[0]; }
    }
 
 
It calls for Zones[0] which doesn't exist, since the zone was never added to the list.
 
Any ideas? Am I running the test incorrectly?
Closed Feb 17, 2009 at 9:58 PM by TheJeepinator
This is a non-issue for most people, some support for older hardware is being worked on.

comments

Lukies97 wrote Jan 4, 2009 at 3:46 AM

It Seems the exception occurs when this line of code is run in the NormalMap.cs file:

NormalTexture = new Texture2D(device, heightMap.Width, heightMap.Height, 0, TextureUsage.AutoGenerateMipMap, SurfaceFormat.Color);

Does the height or width depend on screen resolution maybe?

Lukies97 wrote Jan 4, 2009 at 8:24 PM

It turns out the error was creating an Arguments exception when running the above line of code. That exception was caught, however there is a TODO statement to actually handle said error. I don't think my device supports the number of levels being set to 0 with autogeneeratemipmap as the usage. So I changed this line to 1 and it worked. The engine opened. Except I seemed to have a flat sky with numerous moons showing up. The sunrise, sunset, moonrise, and moonset seemed to work fine though.

wrote Jan 4, 2009 at 8:25 PM

Lukies97 wrote Jan 4, 2009 at 9:09 PM

I added a try catch before and after the NormalTexture line. This takes into account both scenarios of 0 and 1.

Lukies97 wrote Jan 6, 2009 at 3:38 PM

This was an issue with the number of levels for autogenerated mipmaps. If devices do not support this mode, the number of levels needs to be set to 1 instead of 0.

** Closed by Lukies97 1/4/2009 12:25 PM

Lukies97 wrote Jan 6, 2009 at 3:38 PM

While I got the code to compile the error is still in the code. It turns out that some video cards only accept height and width sizes for a texture that is a power of 2. The heightMap is of size 1024 x 1024, however when it is created it stores the height and width value at 1025 for some reason.

wrote Jan 6, 2009 at 3:39 PM

TheJeepinator wrote Jan 11, 2009 at 5:43 PM

We may take a look at not generating mipmaps for the normal texture, im not sure we want to do that anyway when I think about it.

wrote Jan 11, 2009 at 5:43 PM

TheJeepinator wrote Jan 12, 2009 at 6:47 AM

Ok after a little though here is a temporary solution to your problem. Your card does not support uv wrapping or mipmaps on non power of 2 textures so change the constructor for the normalmap to the following:


public



NormalMap(HeightMap heightMap, int verticalScale, int horizontalScale)



{

NormalStore =


new Vector3[heightMap.Width - 1, heightMap.Height - 1];



NormalTexture =


new Texture2D(Engine.GraphicsDevice, heightMap.Width - 1, heightMap.Height - 1, 0, TextureUsage.AutoGenerateMipMap, SurfaceFormat.Color);



GenerateVertexNormals(heightMap.Width - 1, heightMap.Height - 1,


ref heightMap.HeightStore, verticalScale, horizontalScale);



}


This will fix your problem. I am woring up a grapihics manager that will handle figuring out what the card can do and allow components to modify their behavior accordingly

wrote Jan 12, 2009 at 7:00 AM

wrote Feb 17, 2009 at 9:58 PM

wrote Feb 13, 2013 at 12:37 AM

wrote May 14, 2013 at 10:15 PM