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.
This commit is contained in:
12
third_party/xatlas/xatlas.cpp
vendored
12
third_party/xatlas/xatlas.cpp
vendored
@@ -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 <typename T>
|
||||
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<Vector3, uint32_t, Vector3Hash, Vector3Equal> positionMap(vertexCount);
|
||||
HashMap<Vector3, uint32_t, Vector3Hash> positionMap(vertexCount);
|
||||
for (uint32_t i = 0; i < m_positions.size(); i++)
|
||||
positionMap.add(m_positions[i], i);
|
||||
Array<uint32_t> colocals;
|
||||
|
||||
Reference in New Issue
Block a user