static double bbHeight(GeometryBase[] objects, Vector3d zAxis)
{
var tx = Transform.ChangeBasis(Plane.WorldXY, new Plane(Point3d.Origin, zAxis));
var bb = BoundingBox.Empty;
foreach (var obj in objects)
{
bb = BoundingBox.Union(obj.GetBoundingBox(tx), bb);
}
return bb.Max[2] - bb.Min[2];
}
//only difference from bbHeight is that the object is duplicated
//before the bounding box is calculated
static double bbHeight2(GeometryBase[] objects, Vector3d zAxis)
{
var tx = Transform.ChangeBasis(Plane.WorldXY, new Plane(Point3d.Origin, zAxis));
var bb = BoundingBox.Empty;
foreach (var obj in objects)
{
bb = BoundingBox.Union(obj.Duplicate().GetBoundingBox(tx), bb);
}
return bb.Max[2] - bb.Min[2];
}
...
// Crashes from Rhino.Inside, safe in Rhino plugin command (with tests run so far)
Parallel.For(0, zAxes.Length, i => bbHeight(objects, zAxes[i]));
// Safe in both Rhino.Inside and Rhino command plugin ()
Parallel.For(0, zAxes.Length, i => bbHeight2(objects, zAxes[i]));
Hello.
I am trying to understand why the above code causes my program to crash. I have tested that the method GeometryBase.GetBoundingBox(Transform) method does not transform the object, so I don’t understand why the object would need to be duplicated when the loop is run in parallel. I am also curious why this crashes when called from a console application (RhinoInside), but not from within a Rhino plugin.
Any help or advice would be appreciated. Thanks