Fix #29444: cycles problem building BVH with NaN vertices.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 3 Dec 2011 20:22:21 +0000 (20:22 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 3 Dec 2011 20:22:21 +0000 (20:22 +0000)
intern/cycles/bvh/bvh_build.cpp
intern/cycles/util/util_boundbox.h
intern/cycles/util/util_math.h

index 67cff3f5873b4be6edcbecb87ea39e9cfcf85eaa..38674c2c5611da943387111de49ca47a7bc82ea3 100644 (file)
@@ -59,16 +59,18 @@ void BVHBuild::add_reference_mesh(NodeSpec& root, Mesh *mesh, int i)
                Mesh::Triangle t = mesh->triangles[j];
                Reference ref;
 
-               ref.prim_index = j;
-               ref.prim_object = i;
-
                for(int k = 0; k < 3; k++) {
                        float3 pt = mesh->verts[t.v[k]];
                        ref.bounds.grow(pt);
                }
 
-               references.push_back(ref);
-               root.bounds.grow(ref.bounds);
+               if(ref.bounds.valid()) {
+                       ref.prim_index = j;
+                       ref.prim_object = i;
+
+                       references.push_back(ref);
+                       root.bounds.grow(ref.bounds);
+               }
        }
 }
 
index 34cc1d6e11c9a8a20c17cb7eb28e01cb6867975e..b4c5e4e71ca84d9b46e1901d344a66eacf271db1 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <float.h>
 
+#include "util_math.h"
 #include "util_transform.h"
 #include "util_types.h"
 
@@ -71,7 +72,9 @@ public:
 
        bool valid(void) const
        {
-               return (min.x <= max.x) && (min.y <= max.y) && (min.z <= max.z);
+               return (min.x <= max.x) && (min.y <= max.y) && (min.z <= max.z) &&
+                      !(isnan(min.x) || isnan(min.y) || isnan(min.z)) &&
+                      !(isnan(max.x) || isnan(max.y) || isnan(max.z));
        }
 
        BoundBox transformed(const Transform *tfm)
index 2f9e00dbfcbab08e7159b8f8f32a1ae781d01865..7c56f0fbb124fcc10eb435766998044fe07842d7 100644 (file)
@@ -63,6 +63,7 @@ CCL_NAMESPACE_BEGIN
 #if(!defined(FREE_WINDOWS))
 #define copysignf(x, y) ((float)_copysign(x, y))
 #define hypotf(x, y) _hypotf(x, y)
+#define isnan(x) _isnan(x)
 #endif
 
 #endif