Skip to content

Commit

Permalink
Exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tetov committed Feb 16, 2021
1 parent bb97cec commit 0092d7c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/components/ParallellSrfCPDistComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ protected override void SolveInstance(IGH_DataAccess DA)
Surface srf = null;
var pts = new List<Point3d>();

if (!DA.GetDataList(_inSamplePtsIdx, pts))
try
{
return;
if (!DA.GetDataList(_inSamplePtsIdx, pts))
{
return;
}
}
catch (System.OutOfMemoryException)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Too many points to access, out of memory error.");
}

if (!DA.GetData(_inSrfIdx, ref srf))
Expand All @@ -102,11 +109,7 @@ private List<double> GetDistances(SolveData solveData)
{
var dists = new double[solveData.Pts.Count];

// Load balance = True, based on the assumption that this operation's
// execution time varies.
// var partitioner = Partitioner.Create(Enumerable.Range(0, pts.Length).ToList(), true);

// Larger ranges to use be able top update thread specific u1 and v1.
// Static parts
var partitioner = Partitioner.Create(0, solveData.Pts.Count);

_ = Parallel.ForEach(partitioner, (range, loopstate) => ComputeRange(dists, solveData, range, loopstate));
Expand All @@ -120,14 +123,14 @@ private static void ComputeRange(in double[] resultList, SolveData solveData, Tu
{
if (!solveData.Srf.ClosestPoint(solveData.Pts[i], out double u, out double v))
{
// AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Closest point not found.");
loopstate.Break();
throw new System.Exception("No point found on surface.");
}
resultList[i] = solveData.Pts[i].DistanceTo(solveData.Srf.PointAt(u, v));
}
// GC.Collect(2, GCCollectionMode.Optimized);
}

// TODO: This should be tested more to see if there's any impact.
protected override void AfterSolveInstance() => GC.Collect();

public readonly struct SolveData
Expand Down

0 comments on commit 0092d7c

Please sign in to comment.