VolumeMassProperties.Compute6() attempting to access protected memory

Hi all, I am getting this exception on occasion when using VolumeMassProperties.

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at UnsafeNativeMethods.ON_Geometry_VolumeMassProperties(IntPtr pConstGeometryArray, Boolean bVolume, Boolean bFirstMoments, Boolean bSecondMoments, Boolean bProductMoments, Double relativeTolerance, Double absoluteTolerance)
at Rhino.Geometry.VolumeMassProperties.Compute(IEnumerable1 geometry, Boolean volume, Boolean firstMoments, Boolean secondMoments, Boolean productMoments) at Rhino.Geometry.VolumeMassProperties.Compute(IEnumerable1 geometry)
— End of inner exception stack trace —

pls paste here what is your code that we can understand why

I pass lists of breps into this:

def getClosedBrep_vol_properties( surfs ):

    volume = []

    centroid = []

    for srf in surfs:

        if not isinstance(srf,(list,tuple)):

            srf = [srf]     

        result = compute_rhino3d.VolumeMassProperties.Compute6(srf)      

        volume.append(result['Volume'])

        centroid.append(result['Centroid'])

    return volume,centroid

Does this happen with any brep or do I need a specific sample?

I can’t reliably and consistently repeat it Steve, it happens occasionally. It’s occurring on breps not typically visible/accessible to a user at that point, but I’ve put in some code to write the offending surfaces to file next time, so hopefully will be able to provide some in the near future.

@stevebaer I have a surface that I can use to recreate the issue.

It doesn’t happen every time this surface is passed in. In the example code below I’ve passed in an array of 300 surfaces, and when I do this I reliably trigger the exception and knock our compute server down.

But If I reduce the array length to 2, for example, it will typically run fine and not raise an exception.

My test code:


import compute_rhino3d.Brep as Brep
import compute_rhino3d.VolumeMassProperties as VolumeMassProperties
import compute_rhino3d as rc
import rhino3dm
import os

rc.Util.apiKey = 
rc.Util.url =

def get_objects_by_layer_name(model, layer_name):
	layer = model.Layers.FindName(layer_name,0)
	objects = list(filter(lambda o: o.Attributes.LayerIndex == layer.Index, model.Objects))
	return objects



def getClosedBrep_vol_properties( surfs ):

    volume = []

    centroid = []

    for srf in surfs:

        if not isinstance(srf,(list,tuple)):

            srf = [srf]     

        result = VolumeMassProperties.Compute6(srf)      

        volume.append(result['Volume'])

        centroid.append(result['Centroid'])

    return volume,centroid



model = rhino3dm.File3dm.Read("rc_volume_mass_properties_exception.3dm")

srf = get_objects_by_layer_name( model, "Default")[0].Geometry

print( getClosedBrep_vol_properties( [srf]*300 ) )

rc_volume_mass_properties_exception.3dm (116.3 KB)

Thanks; I’ll try to reproduce this on my system.

Any luck @stevebaer ?

Sorry, I haven’t had a chance yet to try and reproduce the issue.

Memory leak? I’ve now seen it take down the server after multiple small calls, no large calls.