Mesh.Reduce() exception


I’m having issues while using the Mesh.Reduce(...) on any mesh (also a simple sphere).
The RhinoCommon version I am using is 7.20.22193.9001.

As an example, this is a python script reproducing the issue:

import sys
import rhinoscriptsyntax as rs
from Rhino import RhinoApp
from Rhino.Geometry import Mesh, ReduceMeshParameters
from exceptions import Exception

if __name__ == '__main__':
    # Select a mesh before running this script.
    obj = rs.SelectedObjects()[0]
    mesh = rs.coercemesh(obj)
    if mesh:
        params = ReduceMeshParameters()
        params.DesiredPolygonCount = 2000
        params.Accuracy = 5
            # The following line ALWAYS throws a null reference exception
            # inside RhinoCommon.
            success = mesh.Reduce(params, threaded=True)
            print("Reduced" if success else "Not reduced")
        except Exception as e:
            print("EXCEPTION: " + str(e))
        print("Mesh is null")

The method keeps crashing even if the DesiredPolygonCount and Accuracy values are lowered, or threaded argument is toggled.

Am I missing something?
Thank you

Hmm, I do see EXCEPTION: Object reference not set to an instance of an object when using the method passing ReduceMeshParameters.

On the other hand, something like this works:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

mesh_id = rs.GetObject("Select mesh",32,preselect=True)
if mesh_id:
    mesh = rs.coercemesh(mesh_id)
    success = mesh.Reduce(targ_count,True,accuracy,False,True)
    if success:
        print "Unable to reduce mesh"

Thank you @Helvetosaur, that was fast! :smiley:
I tried the Reduce(int, bool, int, bool, bool) version of the method, and it works for me as well.

Evidently the issue only affects the Reduce(ReduceMeshParameters, bool) version.


@dale - maybe need to look at this?