From 7931e764a19ef6b21b443376c699bbc9c6d4fba8 Mon Sep 17 00:00:00 2001 From: Daniel Fiser Date: Sat, 22 Dec 2018 13:13:45 +0100 Subject: [PATCH] Fixed divison by zero in the computation of a direction vector in ccdMPRPenetration. (fixes #49) In some cases, a touching contact is found in the findPenetr function. In this case the direction vector is set to (0, 0, 0). --- src/mpr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/mpr.c b/src/mpr.c index b5d4ed0..2ad6c87 100644 --- a/src/mpr.c +++ b/src/mpr.c @@ -328,7 +328,16 @@ static void findPenetr(const void *obj1, const void *obj2, const ccd_t *ccd, &ccdSimplexPoint(portal, 3)->v, pdir); *depth = CCD_SQRT(*depth); - ccdVec3Normalize(pdir); + if (ccdIsZero(*depth)){ + // If depth is zero, then we have a touching contact. + // So following findPenetrTouch(), we assign zero to + // the direction vector (it can actually be anything + // according to the decription of ccdMPRPenetration + // function). + ccdVec3Copy(pdir, ccd_vec3_origin); + }else{ + ccdVec3Normalize(pdir); + } // barycentric coordinates: findPos(obj1, obj2, ccd, portal, pos);