[Bug] NullReferenceException after splitting a BrepFace


(Menno Deij - van Rijswijk) #1

This is on SR4.

When I run the command as below on a simple surface drawn with the Plane command for example, a NullReferenceException ensues when getting the OuterLoop on the second face.

If I first convert the BrepFace to a Brep and then take the first face, the problem goes away. (see “uncomment this to …” in the code below)

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    ObjRef sRef;
    Result res = RhinoGet.GetOneObject("Select a surface", false, ObjectType.Surface, out sRef);
    if (res != Result.Success)
        return res;

    BrepFace face = sRef.Surface() as BrepFace;
    if (null == face)
        return Result.Failure;

    Curve iso = face.UnderlyingSurface().IsoCurve(0, face.UnderlyingSurface().Domain(1).Mid);
    Brep splitted = face.Split(new[]{iso}, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);//RhinoMath.ZeroTolerance);
        
    BrepFace f0 = splitted.Faces[0];
    BrepFace f1 = splitted.Faces[1];

    /* Uncomment this to not get the NullReferenceException below
    f0 = f0.ToBrep().Faces[0];
    f1 = f1.ToBrep().Faces[0];
        */ 

    Curve outerloop0 = f0.OuterLoop.To3dCurve().ToNurbsCurve();

    doc.Objects.AddCurve(outerloop0, new ObjectAttributes { ColorSource = ObjectColorSource.ColorFromObject, ObjectColor = Color.Red, Name="outerloop0" });

    Curve outerloop1 = f1.OuterLoop.To3dCurve().ToNurbsCurve(); // throws NullReferenceException

    doc.Objects.AddCurve(outerloop1, new ObjectAttributes { ColorSource = ObjectColorSource.ColorFromObject, ObjectColor = Color.Red, Name="outerloop1" });

    return Result.Success;
}

(Menno Deij - van Rijswijk) #2

Another problem is that the first outerloop (which does not give an exception) is incorrect.

@stevebaer or @dale would you be so kind to shed your light on this? Much obliged :smile:


(Steve Baer) #3

I’m looking into this right now.


(Menno Deij - van Rijswijk) #4

Cool, thanks!


(Steve Baer) #5

We found the bug; this should be fixed in SR7.


(Menno Deij - van Rijswijk) #6

Excellent, thanks @stevebaer . We use the BrepFace object and its OuterLoop and TrimAwareIsoCurves method in one or our main algorithms. Glad to know that the bug is found and squashed :smile: