diff options
author | Graham Madarasz <graham@lindenlab.com> | 2013-06-12 09:16:19 -0700 |
---|---|---|
committer | Graham Madarasz <graham@lindenlab.com> | 2013-06-12 09:16:19 -0700 |
commit | d2b253f1f6072beead770519849ad3b18a1a4359 (patch) | |
tree | c50dcc7ea602746d156e24a9127721a95f640007 /indra/llappearance/llpolymorph.cpp | |
parent | 48324a93833cee8aca7559588ee5f2b4afa250fa (diff) |
Changes to protect against use of normalize3fast on degenerate vectors
Diffstat (limited to 'indra/llappearance/llpolymorph.cpp')
-rw-r--r-- | indra/llappearance/llpolymorph.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/indra/llappearance/llpolymorph.cpp b/indra/llappearance/llpolymorph.cpp index 8a17819083..5e5813b9ac 100644 --- a/indra/llappearance/llpolymorph.cpp +++ b/indra/llappearance/llpolymorph.cpp @@ -568,6 +568,12 @@ void LLPolyMorphTarget::apply( ESex avatar_sex ) F32 *maskWeightArray = (mVertMask) ? mVertMask->getMorphMaskWeights() : NULL; + LLVector4a default_norm; + LLVector4a default_binorm; + + default_norm.set(0,1,0,1); + default_binorm.set(1,0,0,1); + for(U32 vert_index_morph = 0; vert_index_morph < mMorphData->mNumIndices; vert_index_morph++) { S32 vert_index_mesh = mMorphData->mVertexIndices[vert_index_morph]; @@ -597,19 +603,31 @@ void LLPolyMorphTarget::apply( ESex avatar_sex ) norm.mul(delta_weight*maskWeight*NORMAL_SOFTEN_FACTOR); scaled_normals[vert_index_mesh].add(norm); norm = scaled_normals[vert_index_mesh]; - norm.normalize3fast(); + + // guard against degenerate input data before we create NaNs below! + // + norm.normalize3fast_checked(&default_norm); normals[vert_index_mesh] = norm; // calculate new binormals LLVector4a binorm = mMorphData->mBinormals[vert_index_morph]; + + // guard against degenerate input data before we create NaNs below! + // + if (!binorm.isFinite3() || (binorm.dot3(binorm).getF32() <= F_APPROXIMATELY_ZERO)) + { + binorm.set(1,0,0,1); + } + binorm.mul(delta_weight*maskWeight*NORMAL_SOFTEN_FACTOR); scaled_binormals[vert_index_mesh].add(binorm); LLVector4a tangent; tangent.setCross3(scaled_binormals[vert_index_mesh], norm); LLVector4a& normalized_binormal = binormals[vert_index_mesh]; - normalized_binormal.setCross3(norm, tangent); - normalized_binormal.normalize3fast(); - + + normalized_binormal.setCross3(norm, tangent); + normalized_binormal.normalize3fast_checked(&default_binorm); + tex_coords[vert_index_mesh] += mMorphData->mTexCoords[vert_index_morph] * delta_weight * maskWeight; } |