a small problem, first time user

Topics: User Forum
Feb 4, 2011 at 8:56 PM
Edited Feb 4, 2011 at 9:22 PM

Hi, so I started playing around with farseer today (version 3.1), now sadly I encountered a small issue

I loaded a texture in xna and then simply did the following code:

uint[] data = new uint[i_PlayerTexture.Width * i_PlayerTexture.Height];
 i_PlayerTexture.GetData(data);
 Vertices verts = PolygonTools.CreatePolygon(data, i_PlayerTexture.Width, i_PlayerTexture.Height, true);
Vector2 scale = new Vector2(0.07f, 0.07f);
 verts.Scale(ref scale);
 List<Vertices> _list = BayazitDecomposer.ConvexPartition(verts);
List<Fixture> compund = FixtureFactory.CreateCompoundPolygon(m_World, _list, 1);
compund[0].Body.BodyType = BodyType.Dynamic;

 

which is pretty much a copy-paste of the tutorial's part where you use a texture to create a fixture, of course I got a world initialized somewhere else in the code
so I ran the code, just to see it doesn't crash so I can continue further with it, and... it did crash.

so I tracked it down and the crash happens in class BayazitDecomposer

in this function:

private static Vector2 At(int i, Vertices vertices)
{
     int s = vertices.Count;
    return vertices[i < 0 ? s - (-i % s) : i % s];
 }

the line that crash the code is "return vertices[i < 0 ? s - (-i % s) : i % s];" (value at the crash - [true ? 1 - 0 : 0] )
and the error is index out of range, now the call stack goes pretty far from my call, goes through quite a few of farseer's functions, it's origin in my code is this line:
List<Vertices> _list = BayazitDecomposer.ConvexPartition(verts);

I was hoping someone could tell me what could have went wrong.

thanks.

Coordinator
Feb 5, 2011 at 12:30 AM

The decomposers are pretty picky. Try another one like the EarclipDecomposer.

Feb 5, 2011 at 10:05 AM

And... it actually worked!

Thanks a lot Genbox!