From 2687bf99d6574ca09d13e577a2476ef800193e0a Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Mon, 20 May 2019 14:35:58 -0700 Subject: [PATCH] xatlas: fix crash caused by faulty spatial hash. If A and B are equal keys, then hash(A) and hash(B) should be equal, but xatlas was violating this constraint. This bug was not present in Thekla's original code, it was introduced later by the xatlas project. --- third_party/xatlas/xatlas.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/third_party/xatlas/xatlas.cpp b/third_party/xatlas/xatlas.cpp index 771b6ae147..a450d473d4 100644 --- a/third_party/xatlas/xatlas.cpp +++ b/third_party/xatlas/xatlas.cpp @@ -646,7 +646,7 @@ static Vector3 normalizeSafe(const Vector3 &v, const Vector3 &fallback, float ep static bool equal(const Vector3 &v0, const Vector3 &v1, float epsilon = XA_EPSILON) { - return fabs(v0.x - v1.x) <= epsilon && fabs(v0.y - v1.y) <= epsilon && fabs(v0.z - v1.z) <= epsilon; + return equal(v0.x, v1.x, epsilon) && equal(v0.y, v1.y, epsilon) && equal(v0.z, v1.z, epsilon); } static Vector3 min(const Vector3 &a, const Vector3 &b) @@ -678,14 +678,6 @@ struct Vector3Hash } }; -struct Vector3Equal -{ - bool operator()(const Vector3 &v0, const Vector3 &v1) const - { - return equal(v0, v1); - } -}; - template static void construct_range(T * ptr, uint32_t new_size, uint32_t old_size) { for (uint32_t i = old_size; i < new_size; i++) { @@ -2793,7 +2785,7 @@ public: void createColocals() { const uint32_t vertexCount = m_positions.size(); - HashMap positionMap(vertexCount); + HashMap positionMap(vertexCount); for (uint32_t i = 0; i < m_positions.size(); i++) positionMap.add(m_positions[i], i); Array colocals;