Ticket #1390: 1390-null-ptr-dereference-m_BoneMatrices.patch

File 1390-null-ptr-dereference-m_BoneMatrices.patch, 2.1 KB (added by Echelon9, 12 years ago)

Proposed fix for m_BoneMatrices null pointer dereference

  • source/graphics/Model.cpp

     
    370370    // that doing so will cause a revalidation of this model (see recursion above).
    371371    m_PositionValid = true;
    372372   
    373     // re-position and validate all props
    374     for (size_t j = 0; j < m_Props.size(); ++j)
     373    if (m_BoneMatrices)
    375374    {
    376         const Prop& prop=m_Props[j];
     375        // re-position and validate all props
     376        for (size_t j = 0; j < m_Props.size(); ++j)
     377        {
     378            const Prop& prop=m_Props[j];
    377379
    378         CMatrix3D proptransform = prop.m_Point->m_Transform;;
    379         if (prop.m_Point->m_BoneIndex != 0xff)
    380         {
    381             CMatrix3D boneMatrix = m_BoneMatrices[prop.m_Point->m_BoneIndex];
    382             if (!worldSpaceBoneMatrices)
    383                 boneMatrix.Concatenate(GetTransform());
    384             proptransform.Concatenate(boneMatrix);
    385         }
    386         else
    387         {
    388             // not relative to any bone; just apply world-space transformation (i.e. relative to object-space origin)
    389             proptransform.Concatenate(m_Transform);
    390         }
     380            CMatrix3D proptransform = prop.m_Point->m_Transform;;
     381            if (prop.m_Point->m_BoneIndex != 0xff)
     382            {
     383                CMatrix3D boneMatrix = m_BoneMatrices[prop.m_Point->m_BoneIndex];
     384                if (!worldSpaceBoneMatrices)
     385                    boneMatrix.Concatenate(GetTransform());
     386                proptransform.Concatenate(boneMatrix);
     387            }
     388            else
     389            {
     390                // not relative to any bone; just apply world-space transformation (i.e. relative to object-space origin)
     391                proptransform.Concatenate(m_Transform);
     392            }
    391393       
    392         prop.m_Model->SetTransform(proptransform);
    393         prop.m_Model->ValidatePosition();
    394     }
     394            prop.m_Model->SetTransform(proptransform);
     395            prop.m_Model->ValidatePosition();
     396        }
    395397
    396     if (m_BoneMatrices)
    397     {
    398398        for (size_t i = 0; i < m_pModelDef->GetNumBones(); i++)
    399399        {
    400400            m_BoneMatrices[i] = m_BoneMatrices[i] * m_pModelDef->GetInverseBindBoneMatrices()[i];