Merge pull request #2718 from erwincoumans/master

fix uninitialized variables in btSoftBody: if you add new variables, …
This commit is contained in:
erwincoumans 2020-04-06 20:34:55 -07:00 committed by GitHub
commit 034c6b36ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -222,6 +222,9 @@ void btSoftBody::initDefaults()
m_useSelfCollision = false; m_useSelfCollision = false;
m_usePostCollisionDamping = false; m_usePostCollisionDamping = false;
m_collisionFlags = 0; m_collisionFlags = 0;
m_maxSpeedSquared = 0;
m_repulsionStiffness = 0.5;
m_fdbvnt = 0;
} }
// //
@ -3423,7 +3426,7 @@ void btSoftBody::setSpringStiffness(btScalar k)
{ {
m_links[i].Feature::m_material->m_kLST = k; m_links[i].Feature::m_material->m_kLST = k;
} }
repulsionStiffness = k; m_repulsionStiffness = k;
} }
void btSoftBody::initializeDmInverse() void btSoftBody::initializeDmInverse()

View File

@ -724,6 +724,15 @@ public:
/* SolverState */ /* SolverState */
struct SolverState struct SolverState
{ {
//if you add new variables, always initialize them!
SolverState()
:sdt(0),
isdt(0),
velmrg(0),
radmrg(0),
updmrg(0)
{
}
btScalar sdt; // dt*timescale btScalar sdt; // dt*timescale
btScalar isdt; // 1/sdt btScalar isdt; // 1/sdt
btScalar velmrg; // velocity margin btScalar velmrg; // velocity margin
@ -810,7 +819,7 @@ public:
btScalar m_sleepingThreshold; btScalar m_sleepingThreshold;
btScalar m_maxSpeedSquared; btScalar m_maxSpeedSquared;
btAlignedObjectArray<btVector3> m_quads; // quadrature points for collision detection btAlignedObjectArray<btVector3> m_quads; // quadrature points for collision detection
btScalar repulsionStiffness; btScalar m_repulsionStiffness;
btAlignedObjectArray<btVector3> m_X; // initial positions btAlignedObjectArray<btVector3> m_X; // initial positions
btAlignedObjectArray<btVector4> m_renderNodesInterpolationWeights; btAlignedObjectArray<btVector4> m_renderNodesInterpolationWeights;
@ -1301,7 +1310,7 @@ public:
btScalar I = 0; btScalar I = 0;
btScalar mass = node->m_im == 0 ? 0 : btScalar(1)/node->m_im; btScalar mass = node->m_im == 0 ? 0 : btScalar(1)/node->m_im;
if (applySpringForce) if (applySpringForce)
I = -btMin(repulsionStiffness * timeStep * d, mass * (OVERLAP_REDUCTION_FACTOR * d / timeStep - vn)); I = -btMin(m_repulsionStiffness * timeStep * d, mass * (OVERLAP_REDUCTION_FACTOR * d / timeStep - vn));
if (vn < 0) if (vn < 0)
I += 0.5 * mass * vn; I += 0.5 * mass * vn;
bool face_constrained = false, node_constrained = node->m_constrained; bool face_constrained = false, node_constrained = node->m_constrained;