fix uninitialized variable in btMultiBody

use btAssert to detect 0 determinant in btMatrix3x3 inverse
Remove obsolete comment in PosixSharedMemory, the Windows shared memory implementation was done over a year ago
This commit is contained in:
erwincoumans
2016-09-23 21:59:38 -07:00
parent 666c8f47b7
commit fe6c8775da
5 changed files with 27 additions and 4 deletions

View File

@@ -122,10 +122,15 @@ btMultiBody::btMultiBody(int n_links,
m_useGlobalVelocities(false),
m_internalNeedsJointFeedback(false)
{
m_cachedInertiaTopLeft.setValue(0,0,0,0,0,0,0,0,0);
m_cachedInertiaTopRight.setValue(0,0,0,0,0,0,0,0,0);
m_cachedInertiaLowerLeft.setValue(0,0,0,0,0,0,0,0,0);
m_cachedInertiaLowerRight.setValue(0,0,0,0,0,0,0,0,0);
m_cachedInertiaValid=false;
m_links.resize(n_links);
m_matrixBuf.resize(n_links + 1);
m_baseForce.setValue(0, 0, 0);
m_baseTorque.setValue(0, 0, 0);
}
@@ -1012,6 +1017,7 @@ void btMultiBody::computeAccelerationsArticulatedBodyAlgorithmMultiDof(btScalar
{
if (num_links > 0)
{
m_cachedInertiaValid = true;
m_cachedInertiaTopLeft = spatInertia[0].m_topLeftMat;
m_cachedInertiaTopRight = spatInertia[0].m_topRightMat;
m_cachedInertiaLowerLeft = spatInertia[0].m_bottomLeftMat;
@@ -1215,6 +1221,14 @@ void btMultiBody::solveImatrix(const btVector3& rhs_top, const btVector3& rhs_bo
result[5] = rhs_top[2] / m_baseMass;
} else
{
if (!m_cachedInertiaValid)
{
for (int i=0;i<6;i++)
{
result[i] = 0.f;
}
return;
}
/// Special routine for calculating the inverse of a spatial inertia matrix
///the 6x6 matrix is stored as 4 blocks of 3x3 matrices
btMatrix3x3 Binv = m_cachedInertiaTopRight.inverse()*-1.f;
@@ -1261,6 +1275,13 @@ void btMultiBody::solveImatrix(const btSpatialForceVector &rhs, btSpatialMotionV
{
/// Special routine for calculating the inverse of a spatial inertia matrix
///the 6x6 matrix is stored as 4 blocks of 3x3 matrices
if (!m_cachedInertiaValid)
{
result.setLinear(btVector3(0,0,0));
result.setAngular(btVector3(0,0,0));
result.setVector(btVector3(0,0,0),btVector3(0,0,0));
return;
}
btMatrix3x3 Binv = m_cachedInertiaTopRight.inverse()*-1.f;
btMatrix3x3 tmp = m_cachedInertiaLowerRight * Binv;
btMatrix3x3 invIupper_right = (tmp * m_cachedInertiaTopLeft + m_cachedInertiaLowerLeft).inverse();