unity-triangulation2D icon indicating copy to clipboard operation
unity-triangulation2D copied to clipboard

Script error (RefineSubRoutine) when trying to build a mesh

Open gujhack opened this issue 5 years ago • 1 comments

I've generated a list of Vector2 from a Voronoi generator. Each Vector2 is a vertex of a Voronoi cell, ordered clockwise. The triangulation builds a few meshes, then I get this error:

NullReferenceException: Object reference not set to an instance of an object
mattatz.Triangulation2DSystem.Triangulation2D.RefineSubRoutine (System.Single angle, System.Single threshold) (at Assets/scripts/Triangulation2D/Triangulation2D.cs:331)
mattatz.Triangulation2DSystem.Triangulation2D.Refine (System.Single angle, System.Single threshold) (at Assets/scripts/Triangulation2D/Triangulation2D.cs:320)
mattatz.Triangulation2DSystem.Triangulation2D.Triangulate (UnityEngine.Vector2[] points, System.Single angle, System.Single threshold) (at Assets/scripts/Triangulation2D/Triangulation2D.cs:181)
mattatz.Triangulation2DSystem.Triangulation2D..ctor (mattatz.Triangulation2DSystem.Polygon2D polygon, System.Single angle, System.Single threshold) (at Assets/scripts/Triangulation2D/Triangulation2D.cs:44)
Region..ctor (UnityEngine.Vector2 spawn, System.Collections.Generic.List`1[T] vertices) (at Assets/scripts/Region.cs:23)
VoronoiDemo.Generate () (at Assets/scripts/VoronoiDemo.cs:80)
VoronoiDemo.OnValidate () (at Assets/scripts/VoronoiDemo.cs:51)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

gujhack avatar Apr 29 '20 15:04 gujhack

Hi, I had the same issue, for now I locally just added a guard clause to RefineSubRoutine if "skinny is null", that worked so far. Did not dig deeper, but I prepared a sample for reproduction:

Hope this helps in analyzing and fixing.

        private void ReproduceIssue4()
        {
            var data = new[]
            {
                new Vector2(-43.819f,388.151f),
                new Vector2(-38.41f,400.137f),
                new Vector2(-28.355f,401.522f),
                new Vector2(46.671f,400.616f),
                new Vector2(56.05f,397.882f),
                new Vector2(56.05f,376.922f),
                new Vector2(45.996f,375.537f),
                new Vector2(-34.44f,385.418f),
            };

            (new Triangulation2D(new Polygon2D(data))).Build();
        }

Oppodelldog avatar Dec 25 '21 02:12 Oppodelldog