StaticTriangleGroup.initializeData throws an error

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Jesseyay
Posts: 4
Joined: Wed May 21, 2008 12:22 pm

StaticTriangleGroup.initializeData throws an error

Post by Jesseyay »

When I try to call this method with a list of StaticTriangleGroupVertecies an ArgumentOutOfRangeExceptoin is thrown.
The data I am passing to this function is all correct and I have no idea whats going wrong. Any help would be appreciated.

Below is a copy of the exceptoin detal. (I'm using Microsoft Visual C# 2005).

Thanks.

Code: Select all

System.ArgumentOutOfRangeException was unhandled
  Message="Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"
  Source="mscorlib"
  ParamName="index"
  StackTrace:
       at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
       at System.ThrowHelper.ThrowArgumentOutOfRangeException()
       at System.Collections.Generic.List`1.get_Item(Int32 index)
       at BEPUphysics.StaticTriangleGroup.buildTree()
       at BEPUphysics.StaticTriangleGroup.initializeData(List`1 triangleVertices)
       at CharacterContolTest.Game1.CreatePhysicsEntities() in C:\Users\Jesse\Documents\Visual Studio 2005\Projects\CharacterContolTest\CharacterContolTest\Game1.cs:line 114
       at CharacterContolTest.Game1.Initialize() in C:\Users\Jesse\Documents\Visual Studio 2005\Projects\CharacterContolTest\CharacterContolTest\Game1.cs:line 213
       at Microsoft.Xna.Framework.Game.Run()
       at CharacterContolTest.Program.Main(String[] args) in C:\Users\Jesse\Documents\Visual Studio 2005\Projects\CharacterContolTest\CharacterContolTest\Program.cs:line 14
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: StaticTriangleGroup.initializeData throws an error

Post by Norbo »

I believe this problem is caused by giving the initializeData method vertexbuffer data that originally had an index buffer alongside it. The method expects a 'redundant' list of vertices in which every group of 3 vertices forms another triangle. If the vertex buffer's length isn't divisible by 3, you'll get this error (and some wonky results otherwise). I put some extra clarification in the XML comments accordingly and some more descriptive exceptions in the problem sections.

You'll probably be able to bypass the problem completely if you use the initializeData method which takes both a vertex list and index list (though grabbing an index buffer from a ModelMesh can give you either a short or int, so a little extra precaution has to be taken).
Post Reply