Fix 34764: cycles issue rendering instanced mesh with NaN coordinates.

This commit is contained in:
Brecht Van Lommel 2013-04-09 20:48:53 +00:00
parent 84ba3f6521
commit 34707c19f2
2 changed files with 46 additions and 7 deletions

@ -135,15 +135,29 @@ void Mesh::compute_bounds()
size_t verts_size = verts.size();
size_t curve_keys_size = curve_keys.size();
for(size_t i = 0; i < verts_size; i++)
bnds.grow(verts[i]);
if(verts_size + curve_keys_size > 0) {
for(size_t i = 0; i < verts_size; i++)
bnds.grow(verts[i]);
for(size_t i = 0; i < curve_keys_size; i++)
bnds.grow(curve_keys[i].co, curve_keys[i].radius);
for(size_t i = 0; i < curve_keys_size; i++)
bnds.grow(curve_keys[i].co, curve_keys[i].radius);
/* happens mostly on empty meshes */
if(!bnds.valid())
if(!bnds.valid()) {
bnds = BoundBox::empty;
/* skip nan or inf coordinates */
for(size_t i = 0; i < verts_size; i++)
bnds.grow_safe(verts[i]);
for(size_t i = 0; i < curve_keys_size; i++)
bnds.grow_safe(curve_keys[i].co, curve_keys[i].radius);
}
}
if(!bnds.valid()) {
/* empty mesh */
bnds.grow(make_float3(0.0f, 0.0f, 0.0f));
}
bounds = bnds;
}

@ -80,6 +80,31 @@ public:
grow(bbox.max);
}
__forceinline void grow_safe(const float3& pt)
{
/* the order of arguments to min is such that if pt is nan, it will not
* influence the resulting bounding box */
if(isfinite(pt.x) && isfinite(pt.y) && isfinite(pt.z)) {
min = ccl::min(pt, min);
max = ccl::max(pt, max);
}
}
__forceinline void grow_safe(const float3& pt, float border)
{
if(isfinite(pt.x) && isfinite(pt.y) && isfinite(pt.z) && isfinite(border)) {
float3 shift = {border, border, border, 0.0f};
min = ccl::min(pt - shift, min);
max = ccl::max(pt + shift, max);
}
}
__forceinline void grow_safe(const BoundBox& bbox)
{
grow_safe(bbox.min);
grow_safe(bbox.max);
}
__forceinline void intersect(const BoundBox& bbox)
{
min = ccl::max(min, bbox.min);
@ -120,7 +145,7 @@ public:
{
return max - min;
}
__forceinline bool valid() const
{
return (min.x <= max.x) && (min.y <= max.y) && (min.z <= max.z) &&