Merge pull request #804 from erwincoumans/master

fix uninitialized variable in btMultiBody
This commit is contained in:
erwincoumans
2016-09-23 22:13:36 -07:00
committed by GitHub
5 changed files with 27 additions and 4 deletions

View File

@@ -172,7 +172,7 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, boo
b3Assert(glGetError() ==GL_NO_ERROR);
m_instancingRenderer = new GLInstancingRenderer(128*1024,64*1024*1024);
m_instancingRenderer = new GLInstancingRenderer(128*1024,128*1024*1024);
m_primRenderer = new GLPrimitiveRenderer(width,height);
m_renderer = m_instancingRenderer ;

View File

@@ -2,7 +2,7 @@
#include "Bullet3Common/b3Logging.h"
#include "LinearMath/btScalar.h" //for btAssert
//haven't implemented shared memory on Windows yet, just Linux and Mac
//Windows implementation is in Win32SharedMemory.cpp
#ifndef _WIN32
#define TEST_SHARED_MEMORY
#endif//_WIN32

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();

View File

@@ -677,6 +677,7 @@ private:
btMatrix3x3 m_cachedInertiaTopRight;
btMatrix3x3 m_cachedInertiaLowerLeft;
btMatrix3x3 m_cachedInertiaLowerRight;
bool m_cachedInertiaValid;
bool m_fixedBase;

View File

@@ -1047,7 +1047,8 @@ btMatrix3x3::inverse() const
{
btVector3 co(cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1));
btScalar det = (*this)[0].dot(co);
btFullAssert(det != btScalar(0.0));
//btFullAssert(det != btScalar(0.0));
btAssert(det != btScalar(0.0));
btScalar s = btScalar(1.0) / det;
return btMatrix3x3(co.x() * s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s,
co.y() * s, cofac(0, 0, 2, 2) * s, cofac(0, 2, 1, 0) * s,