gradientspace / geometry3Sharp

C# library for 2D/3D geometric computation, mesh algorithms, and so on. Boost license.
http://www.gradientspace.com
Boost Software License 1.0
1.71k stars 389 forks source link

Crash LaplacianMeshSmoother #110

Open dijame opened 5 years ago

dijame commented 5 years ago

Hello,

I would like to submit a possible issue, i have found in LaplacianMeshSmoother.cs.

In RegionSmooth, line 356. This function crash when my BaseBorderV. Count of my "submesh" is equal to zero. In fact, in this case the "HashSet constrained" is not allocated so when the test if "constrained.Count > 0" the variable is null ! line 407.

line 397 to 407 : (My correction)

        // Old method with crash
        //HashSet<int> constrained = (submesh.BaseBorderV.Count > 0) ? new HashSet<int>() : null;

        HashSet<int> constrained = new HashSet<int>();
        foreach (int base_vid in submesh.BaseBorderV) {
            int sub_vid = submesh.BaseToSubV[base_vid];
            smoother.SetConstraint(sub_vid, smoothMesh.GetVertex(sub_vid), w, true);
            if (constrained != null)
                constrained.Add(sub_vid);
        }

        if (constrained.Count > 0) 

Maybe i'm wrong, let me know about this !