From e584b9c9185698f62bdeadb4dc6fd35a31d9029b Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 14 Apr 2021 09:27:08 -0500 Subject: [PATCH] Prevent divide-by-zero in bins_crossed methods --- src/mesh.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mesh.cpp b/src/mesh.cpp index 19cbeae10a..16ce630ae0 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -594,6 +594,7 @@ void StructuredMesh::bins_crossed(const Particle& p, std::vector& bins, // Compute the length of the entire track. double total_distance = (r - last_r).norm(); + if (total_distance == 0.0) return; // While determining if this track intersects the mesh, offset the starting // and ending coords by a bit. This avoid finite-precision errors that can @@ -1713,6 +1714,7 @@ MOABMesh::bins_crossed(const Particle& p, moab::CartVect dir(u.x, u.y, u.z); double track_len = (r1 - r0).length(); + if (track_len == 0.0) return; r0 -= TINY_BIT * dir; r1 += TINY_BIT * dir;