Skip to content

Commit 9a4f6d4

Browse files
committed
[operations] Fail-proof while loop with safety counter
1 parent 4e4eebc commit 9a4f6d4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/CollisionAlgorithm/operations/NeedleOperations.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ bool prunePointsUsingEdges(std::vector<BaseProximity::SPtr>& couplingPts,
1818

1919
const int initSize = couplingPts.size();
2020

21+
int safeCounter = initSize;
2122
while(!couplingPts.empty())
2223
{
2324
const type::Vec3 tip2Pt = couplingPts.back()->getPosition() - tip;
2425

2526
// Negative dot product means the point is behind the tip
2627
if(dot(tip2Pt, edgeDirection) < 0_sreal) break;
2728
couplingPts.pop_back();
29+
30+
// Temporary safety to avoid infinite loops - remove when confident
31+
safeCounter--;
32+
if (safeCounter < 0)
33+
{
34+
msg_warning("Needle::PrunePointsAheadOfTip") << "Counter expired; breaking loop";
35+
break;
36+
}
2837
}
2938
return (initSize == couplingPts.size());
3039
}

0 commit comments

Comments
 (0)