DocumentCollectedException on custom mesh object when running ReduceMesh

(Menno Deij - van Rijswijk) #1

@stevebaer here is a reproducible crash with a DocumentCollectedException when using ReduceMesh//Preview on a CustomMeshObject. Is there something I’m doing wrong? If so, please advise on how to do it correctly.


protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    ObjRef mRef;
    Result res = RhinoGet.GetOneObject("Select mesh", false, ObjectType.Mesh, out mRef);
    if (res != Result.Success)
        return res;

    Mesh m = mRef.Mesh();
    MyMeshObject my = new MyMeshObject(m);

    doc.Objects.Replace(mRef, my);

    RhinoApp.WriteLine("Now run ReduceMesh on the custom mesh object, give #polygons and press Preview => DocumentCollectedException.");
    return Result.Success;

public class MyMeshObject : CustomMeshObject
    private BoundingBox _bb;
    public MyMeshObject(Mesh m)
        : base(m)
        if (null != m)
            _bb = m.GetBoundingBox(true);

    public MyMeshObject()
        // required

    protected override void OnDuplicate(RhinoObject source)
        MyMeshObject other = source as MyMeshObject;
        if (null != other)
            _bb = other._bb;

    protected override void OnDraw(DrawEventArgs e)
        if (_bb.IsValid)
            e.Display.DrawBox(_bb, Color.Red, 2);

(Steve Baer) #2

Thanks! I’ll try to look at this in the next few days.

(Steve Baer) #3

This will be fixed in SR10. By the way, this has got to be one of the best bug reports ever. Almost no work on my part to try and figure out what to do to repeat the problem :smile: I appreciate that.

Unfortunately the ReduceMesh command will still convert your custom mesh into a regular mesh when the command completes. The real fix for that issue is too big for me to comfortably change at this point in the life cycle of Rhino 5.

(Menno Deij - van Rijswijk) #4

Thanks for fixing this! In our case, running ReduceMesh on our custom mesh object will need to fall back to a normal mesh. We work with structured grids (rows x columns of vertices) and the ReduceMesh command will not preserve that structure.