error with TextureToPolygon

Jan 8, 2011 at 1:32 PM

Hi guys

I've been trying to get the TextureToPolygon code to work, but I've ran into a problem.

Here is the code I use to create a Polygon from a Texture:


uint[] data = new uint[texture.Width * texture.Height];


            Vertices verts = PolygonTools.CreatePolygon(data, texture.Width, texture.Height, true);

            Vector2 scale = new Vector2(0.07f, 0.07f);
            verts.Scale(ref scale);

            List<Vertices> _list = BayazitDecomposer.ConvexPartition(verts);

            List<Fixture> compound = FixtureFactory.CreateCompoundPolygon(world, _list, 1f);

            compound[0].Body.BodyType = BodyType.Static;


The problem is, I get the following error:

"An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll"

the line causing this is this:

/// <summary>
        /// Given a transform, compute the associated axis aligned bounding box for a child shape.
        /// </summary>
        /// <param name="aabb">The aabb results.</param>
        /// <param name="transform">The world transform of the shape.</param>
        /// <param name="childIndex">The child shape index.</param>
        public override void ComputeAABB(out AABB aabb, ref Transform transform, int childIndex)
            >>>>>  Vector2 lower = MathUtils.Multiply(ref transform, Vertices[0]);

..which is called by this..

// These support body activation/deactivation.
        internal void CreateProxies(BroadPhase broadPhase, ref Transform xf)
            Debug.Assert(ProxyCount == 0);

            // Create proxies in the broad-phase.
            ProxyCount = Shape.ChildCount;

            for (int i = 0; i < ProxyCount; ++i)
                FixtureProxy proxy = Proxies[i];
                Shape.ComputeAABB(out proxy.AABB, ref xf, i);

The texture I'm using is just a solid rectangle at the moment, but I plan on using more complicated shapes in the future.

Any help or suggestions?

Jan 8, 2011 at 5:13 PM

Take a look at the data generated by the Texture-To-Vertices algorithm. The List<Vertices> might contain invalid data such as empty vertice collections. However, I believe this should be caught by the engine. Are you running in Debug mode?

Jan 8, 2011 at 5:17 PM

Thanks for the reply,

I've created a simple loop to remove any empty vertice collections from the list, and it seems to run fine now. Just to note, I am running in debug mode. The program stops at the Debug.Assert... lines, which I just F5 past. Once I get the DebugView working tomorrow I can double check it's all working fine, but for now removing the empty entries from the list no longer causes the out of range exception.

Thanks very much!

Jan 8, 2011 at 8:32 PM

I will add some code to remove empty vertice collections when you use the triangulation tools.