From 2529aebc7929d0c2e8a4c4a07f804e4f735dda49 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Fri, 26 May 2006 19:47:46 +0000 Subject: [PATCH] this should not be necessary, but it happened. todo: why doesn't gjk terminate. there are 2 rare cases, one with 'nan'/undefined separating axis/distance, and another with rather big distances. --- .../NarrowPhaseCollision/GjkPairDetector.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Bullet/NarrowPhaseCollision/GjkPairDetector.cpp b/Bullet/NarrowPhaseCollision/GjkPairDetector.cpp index c1f4c4e47..9f20cb6d5 100644 --- a/Bullet/NarrowPhaseCollision/GjkPairDetector.cpp +++ b/Bullet/NarrowPhaseCollision/GjkPairDetector.cpp @@ -23,6 +23,7 @@ SimdScalar rel_error2 = rel_error * rel_error; float maxdist2 = 1.e30f; +int maxIter=1000; GjkPairDetector::GjkPairDetector(ConvexShape* objectA,ConvexShape* objectB,SimplexSolverInterface* simplexSolver,ConvexPenetrationDepthSolver* penetrationDepthSolver) :m_cachedSeparatingAxis(0.f,0.f,1.f), @@ -50,6 +51,8 @@ void GjkPairDetector::GetClosestPoints(const ClosestPointInput& input,Result& ou marginB = 0.f; } +int curIter = 0; + bool isValid = false; bool checkSimplex = false; bool checkPenetration = true; @@ -66,6 +69,21 @@ void GjkPairDetector::GetClosestPoints(const ClosestPointInput& input,Result& ou while (true) { + if (curIter++ > maxIter) +{ +#ifdef DEBUG +printf("GjkPairDetector maxIter exceeded:%i\n",curIter); +printf("sepAxis=(%f,%f,%f), squaredDistance = %f, shapeTypeA=%i,shapeTypeB=%i\n", +m_cachedSeparatingAxis.getX(), +m_cachedSeparatingAxis.getY(), +m_cachedSeparatingAxis.getZ(), +squaredDistance, +m_minkowskiA->GetShapeType(), +m_minkowskiB->GetShapeType()); +#endif +break; + +} SimdVector3 seperatingAxisInA = (-m_cachedSeparatingAxis)* input.m_transformA.getBasis(); SimdVector3 seperatingAxisInB = m_cachedSeparatingAxis* input.m_transformB.getBasis();