From 48a6fe86cab42d8417bf77f481fd131dd6cb0899 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 26 Apr 2013 02:18:29 +0000 Subject: Fix #34172: cycles BVH build crashing in some rare circumstances on 32 bit linux. The problem was (again) the x86 extended precision float register being used for one float value while the other was rounded to lower precision. This caused the strictly weak order requirement for std::sort to be broken. --- intern/cycles/bvh/bvh_sort.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'intern/cycles/bvh/bvh_sort.cpp') diff --git a/intern/cycles/bvh/bvh_sort.cpp b/intern/cycles/bvh/bvh_sort.cpp index 91994be5b96..d7dbae36336 100644 --- a/intern/cycles/bvh/bvh_sort.cpp +++ b/intern/cycles/bvh/bvh_sort.cpp @@ -23,6 +23,15 @@ CCL_NAMESPACE_BEGIN +/* silly workaround for float extended precision that happens when compiling + * on x86, due to one float staying in 80 bit precision register and the other + * not, which causes the strictly weak ordering to break */ +#if !defined(__i386__) +#define NO_EXTENDED_PRECISION +#else +#define NO_EXTENDED_PRECISION volatile +#endif + struct BVHReferenceCompare { public: int dim; @@ -34,8 +43,8 @@ public: bool operator()(const BVHReference& ra, const BVHReference& rb) { - float ca = ra.bounds().min[dim] + ra.bounds().max[dim]; - float cb = rb.bounds().min[dim] + rb.bounds().max[dim]; + NO_EXTENDED_PRECISION float ca = ra.bounds().min[dim] + ra.bounds().max[dim]; + NO_EXTENDED_PRECISION float cb = rb.bounds().min[dim] + rb.bounds().max[dim]; if(ca < cb) return true; else if(ca > cb) return false; @@ -52,7 +61,8 @@ public: void bvh_reference_sort(int start, int end, BVHReference *data, int dim) { - sort(data+start, data+end, BVHReferenceCompare(dim)); + BVHReferenceCompare compare(dim); + sort(data+start, data+end, compare); } CCL_NAMESPACE_END -- cgit v1.2.3