Skip to content

Commit 7365d93

Browse files
authored
Merge pull request #3 from Nutcake/fix-convex-hull-memory-leak
Remove use of unnecessary DebugStep debug object
2 parents 64795ac + 5602eaa commit 7365d93

File tree

1 file changed

+69
-69
lines changed

1 file changed

+69
-69
lines changed

BepuPhysics/Collidables/ConvexHullHelper.cs

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -592,70 +592,70 @@ static void AddIfNotPresent(ref QuickList<int> list, int value, BufferPool pool)
592592
list.Allocate(pool) = value;
593593
}
594594

595-
public struct DebugStep
596-
{
597-
public EdgeEndpoints SourceEdge;
598-
public List<int> Raw;
599-
public List<int> Reduced;
600-
public bool[] AllowVertex;
601-
public Vector3 FaceNormal;
602-
public Vector3 BasisX;
603-
public Vector3 BasisY;
604-
public List<int> FaceStarts;
605-
public List<int> FaceIndices;
606-
public bool[] FaceDeleted;
607-
public int[] MergedFaceIndices;
608-
public int FaceIndex;
609-
public Vector3[] FaceNormals;
610-
611-
internal DebugStep(EdgeEndpoints sourceEdge, ref QuickList<int> raw, Vector3 faceNormal, Vector3 basisX, Vector3 basisY, ref QuickList<int> reduced, ref Buffer<int> allowVertex, ref QuickList<EarlyFace> faces, Span<int> mergedFaceIndices, int faceIndex)
612-
{
613-
SourceEdge = sourceEdge;
614-
FaceNormal = faceNormal;
615-
BasisX = basisX;
616-
BasisY = basisY;
617-
Raw = new List<int>();
618-
for (int i = 0; i < raw.Count; ++i)
619-
{
620-
Raw.Add(raw[i]);
621-
}
622-
Reduced = new List<int>();
623-
for (int i = 0; i < reduced.Count; ++i)
624-
{
625-
Reduced.Add(reduced[i]);
626-
}
627-
AllowVertex = new bool[allowVertex.Length];
628-
for (int i = 0; i < allowVertex.Length; ++i)
629-
{
630-
AllowVertex[i] = allowVertex[i] != 0;
631-
}
632-
FaceStarts = new List<int>(faces.Count);
633-
FaceIndices = new List<int>();
634-
FaceDeleted = new bool[faces.Count];
635-
FaceNormals = new Vector3[faces.Count];
636-
for (int i = 0; i < faces.Count; ++i)
637-
{
638-
ref var face = ref faces[i];
639-
FaceStarts.Add(FaceIndices.Count);
640-
for (int j = 0; j < face.VertexIndices.Count; ++j)
641-
FaceIndices.Add(face.VertexIndices[j]);
642-
FaceDeleted[i] = face.Deleted;
643-
FaceNormals[i] = face.Normal;
644-
}
645-
MergedFaceIndices = mergedFaceIndices.ToArray();
646-
FaceIndex = faceIndex;
647-
}
648-
}
649-
/// <summary>
650-
/// Computes the convex hull of a set of points.
651-
/// </summary>
652-
/// <param name="points">Point set to compute the convex hull of.</param>
653-
/// <param name="pool">Buffer pool to pull memory from when creating the hull.</param>
654-
/// <param name="hullData">Convex hull of the input point set.</param>
655-
public static void ComputeHull(Span<Vector3> points, BufferPool pool, out HullData hullData)
656-
{
657-
ComputeHull(points, pool, out hullData, out _);
658-
}
595+
//public struct DebugStep
596+
//{
597+
// public EdgeEndpoints SourceEdge;
598+
// public List<int> Raw;
599+
// public List<int> Reduced;
600+
// public bool[] AllowVertex;
601+
// public Vector3 FaceNormal;
602+
// public Vector3 BasisX;
603+
// public Vector3 BasisY;
604+
// public List<int> FaceStarts;
605+
// public List<int> FaceIndices;
606+
// public bool[] FaceDeleted;
607+
// public int[] MergedFaceIndices;
608+
// public int FaceIndex;
609+
// public Vector3[] FaceNormals;
610+
611+
// internal DebugStep(EdgeEndpoints sourceEdge, ref QuickList<int> raw, Vector3 faceNormal, Vector3 basisX, Vector3 basisY, ref QuickList<int> reduced, ref Buffer<int> allowVertex, ref QuickList<EarlyFace> faces, Span<int> mergedFaceIndices, int faceIndex)
612+
// {
613+
// SourceEdge = sourceEdge;
614+
// FaceNormal = faceNormal;
615+
// BasisX = basisX;
616+
// BasisY = basisY;
617+
// Raw = new List<int>();
618+
// for (int i = 0; i < raw.Count; ++i)
619+
// {
620+
// Raw.Add(raw[i]);
621+
// }
622+
// Reduced = new List<int>();
623+
// for (int i = 0; i < reduced.Count; ++i)
624+
// {
625+
// Reduced.Add(reduced[i]);
626+
// }
627+
// AllowVertex = new bool[allowVertex.Length];
628+
// for (int i = 0; i < allowVertex.Length; ++i)
629+
// {
630+
// AllowVertex[i] = allowVertex[i] != 0;
631+
// }
632+
// FaceStarts = new List<int>(faces.Count);
633+
// FaceIndices = new List<int>();
634+
// FaceDeleted = new bool[faces.Count];
635+
// FaceNormals = new Vector3[faces.Count];
636+
// for (int i = 0; i < faces.Count; ++i)
637+
// {
638+
// ref var face = ref faces[i];
639+
// FaceStarts.Add(FaceIndices.Count);
640+
// for (int j = 0; j < face.VertexIndices.Count; ++j)
641+
// FaceIndices.Add(face.VertexIndices[j]);
642+
// FaceDeleted[i] = face.Deleted;
643+
// FaceNormals[i] = face.Normal;
644+
// }
645+
// MergedFaceIndices = mergedFaceIndices.ToArray();
646+
// FaceIndex = faceIndex;
647+
// }
648+
//}
649+
///// <summary>
650+
///// Computes the convex hull of a set of points.
651+
///// </summary>
652+
///// <param name="points">Point set to compute the convex hull of.</param>
653+
///// <param name="pool">Buffer pool to pull memory from when creating the hull.</param>
654+
///// <param name="hullData">Convex hull of the input point set.</param>
655+
//public static void ComputeHull(Span<Vector3> points, BufferPool pool, out HullData hullData)
656+
//{
657+
// ComputeHull(points, pool, out hullData, out _);
658+
//}
659659

660660

661661
/// <summary>
@@ -664,9 +664,9 @@ public static void ComputeHull(Span<Vector3> points, BufferPool pool, out HullDa
664664
/// <param name="points">Point set to compute the convex hull of.</param>
665665
/// <param name="pool">Buffer pool to pull memory from when creating the hull.</param>
666666
/// <param name="hullData">Convex hull of the input point set.</param>
667-
public static void ComputeHull(Span<Vector3> points, BufferPool pool, out HullData hullData, out List<DebugStep> steps)
667+
public static void ComputeHull(Span<Vector3> points, BufferPool pool, out HullData hullData)//, out List<DebugStep> steps)
668668
{
669-
steps = new List<DebugStep>();
669+
//steps = new List<DebugStep>();
670670
if (points.Length <= 0)
671671
{
672672
hullData = default;
@@ -825,7 +825,7 @@ public static void ComputeHull(Span<Vector3> points, BufferPool pool, out HullDa
825825
}
826826
Vector3Wide.ReadFirst(initialBasisX, out var debugInitialBasisX);
827827
Vector3Wide.ReadFirst(initialBasisY, out var debugInitialBasisY);
828-
steps.Add(new DebugStep(initialSourceEdge, ref rawFaceVertexIndices, initialFaceNormal, debugInitialBasisX, debugInitialBasisY, ref reducedFaceIndices, ref allowVertices, ref faces, default, reducedFaceIndices.Count >= 3 ? 0 : -1));
828+
//steps.Add(new DebugStep(initialSourceEdge, ref rawFaceVertexIndices, initialFaceNormal, debugInitialBasisX, debugInitialBasisY, ref reducedFaceIndices, ref allowVertices, ref faces, default, reducedFaceIndices.Count >= 3 ? 0 : -1));
829829

830830
int facesDeletedCount = 0;
831831

@@ -858,7 +858,7 @@ public static void ComputeHull(Span<Vector3> points, BufferPool pool, out HullDa
858858

859859
if (reducedFaceIndices.Count < 3)
860860
{
861-
steps.Add(new DebugStep(edgeToTest.Endpoints, ref rawFaceVertexIndices, faceNormal, basisX, basisY, ref reducedFaceIndices, ref allowVertices, ref faces, default, -1));
861+
//steps.Add(new DebugStep(edgeToTest.Endpoints, ref rawFaceVertexIndices, faceNormal, basisX, basisY, ref reducedFaceIndices, ref allowVertices, ref faces, default, -1));
862862
//Degenerate face found; don't bother creating work for it.
863863
continue;
864864
}
@@ -984,7 +984,7 @@ public static void ComputeHull(Span<Vector3> points, BufferPool pool, out HullDa
984984

985985
AddFace(ref faces, pool, faceNormal, reducedFaceIndices);
986986
AddFaceToEdgesAndTestList(pool, ref reducedFaceIndices, ref edgesToTest, ref facesForEdges, faceNormal, faceCountPriorToAdd);
987-
steps.Add(new DebugStep(edgeToTest.Endpoints, ref rawFaceVertexIndices, faceNormal, basisX, basisY, ref reducedFaceIndices, ref allowVertices, ref faces, facesNeedingMerge, faceCountPriorToAdd));
987+
//steps.Add(new DebugStep(edgeToTest.Endpoints, ref rawFaceVertexIndices, faceNormal, basisX, basisY, ref reducedFaceIndices, ref allowVertices, ref faces, facesNeedingMerge, faceCountPriorToAdd));
988988
break;
989989
}
990990
}

0 commit comments

Comments
 (0)