constraint solvers: fix crash for collision-bodies with incorrect flags
This commit is contained in:
@@ -738,23 +738,21 @@ int btSequentialImpulseConstraintSolver::getOrInitSolverBody(btCollisionObject&
|
|||||||
{
|
{
|
||||||
#if BT_THREADSAFE
|
#if BT_THREADSAFE
|
||||||
int solverBodyId = -1;
|
int solverBodyId = -1;
|
||||||
if ( !body.isStaticOrKinematicObject() )
|
bool isRigidBodyType = btRigidBody::upcast( &body ) != NULL;
|
||||||
|
if ( isRigidBodyType && !body.isStaticOrKinematicObject() )
|
||||||
{
|
{
|
||||||
// dynamic body
|
// dynamic body
|
||||||
// Dynamic bodies can only be in one island, so it's safe to write to the companionId
|
// Dynamic bodies can only be in one island, so it's safe to write to the companionId
|
||||||
solverBodyId = body.getCompanionId();
|
solverBodyId = body.getCompanionId();
|
||||||
if ( solverBodyId < 0 )
|
if ( solverBodyId < 0 )
|
||||||
{
|
{
|
||||||
if ( btRigidBody* rb = btRigidBody::upcast( &body ) )
|
solverBodyId = m_tmpSolverBodyPool.size();
|
||||||
{
|
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
||||||
solverBodyId = m_tmpSolverBodyPool.size();
|
initSolverBody( &solverBody, &body, timeStep );
|
||||||
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
body.setCompanionId( solverBodyId );
|
||||||
initSolverBody( &solverBody, &body, timeStep );
|
|
||||||
body.setCompanionId( solverBodyId );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (body.isKinematicObject())
|
else if (isRigidBodyType && body.isKinematicObject())
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// NOTE: must test for kinematic before static because some kinematic objects also
|
// NOTE: must test for kinematic before static because some kinematic objects also
|
||||||
@@ -774,7 +772,6 @@ int btSequentialImpulseConstraintSolver::getOrInitSolverBody(btCollisionObject&
|
|||||||
if ( solverBodyId == INVALID_SOLVER_BODY_ID )
|
if ( solverBodyId == INVALID_SOLVER_BODY_ID )
|
||||||
{
|
{
|
||||||
// create a table entry for this body
|
// create a table entry for this body
|
||||||
btRigidBody* rb = btRigidBody::upcast( &body );
|
|
||||||
solverBodyId = m_tmpSolverBodyPool.size();
|
solverBodyId = m_tmpSolverBodyPool.size();
|
||||||
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
||||||
initSolverBody( &solverBody, &body, timeStep );
|
initSolverBody( &solverBody, &body, timeStep );
|
||||||
@@ -792,7 +789,7 @@ int btSequentialImpulseConstraintSolver::getOrInitSolverBody(btCollisionObject&
|
|||||||
}
|
}
|
||||||
solverBodyId = m_fixedBodyId;
|
solverBodyId = m_fixedBodyId;
|
||||||
}
|
}
|
||||||
btAssert( solverBodyId < m_tmpSolverBodyPool.size() );
|
btAssert( solverBodyId >= 0 && solverBodyId < m_tmpSolverBodyPool.size() );
|
||||||
return solverBodyId;
|
return solverBodyId;
|
||||||
#else // BT_THREADSAFE
|
#else // BT_THREADSAFE
|
||||||
|
|
||||||
|
|||||||
@@ -317,7 +317,8 @@ int btSequentialImpulseConstraintSolverMt::getOrInitSolverBodyThreadsafe(btColli
|
|||||||
// getOrInitSolverBodyThreadsafe -- attempts to be fully threadsafe (however may affect determinism)
|
// getOrInitSolverBodyThreadsafe -- attempts to be fully threadsafe (however may affect determinism)
|
||||||
//
|
//
|
||||||
int solverBodyId = -1;
|
int solverBodyId = -1;
|
||||||
if ( !body.isStaticOrKinematicObject() )
|
bool isRigidBodyType = btRigidBody::upcast( &body ) != NULL;
|
||||||
|
if ( isRigidBodyType && !body.isStaticOrKinematicObject() )
|
||||||
{
|
{
|
||||||
// dynamic body
|
// dynamic body
|
||||||
// Dynamic bodies can only be in one island, so it's safe to write to the companionId
|
// Dynamic bodies can only be in one island, so it's safe to write to the companionId
|
||||||
@@ -329,18 +330,15 @@ int btSequentialImpulseConstraintSolverMt::getOrInitSolverBodyThreadsafe(btColli
|
|||||||
solverBodyId = body.getCompanionId();
|
solverBodyId = body.getCompanionId();
|
||||||
if ( solverBodyId < 0 )
|
if ( solverBodyId < 0 )
|
||||||
{
|
{
|
||||||
if ( btRigidBody* rb = btRigidBody::upcast( &body ) )
|
solverBodyId = m_tmpSolverBodyPool.size();
|
||||||
{
|
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
||||||
solverBodyId = m_tmpSolverBodyPool.size();
|
initSolverBody( &solverBody, &body, timeStep );
|
||||||
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
body.setCompanionId( solverBodyId );
|
||||||
initSolverBody( &solverBody, &body, timeStep );
|
|
||||||
body.setCompanionId( solverBodyId );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
m_bodySolverArrayMutex.unlock();
|
m_bodySolverArrayMutex.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (body.isKinematicObject())
|
else if (isRigidBodyType && body.isKinematicObject())
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// NOTE: must test for kinematic before static because some kinematic objects also
|
// NOTE: must test for kinematic before static because some kinematic objects also
|
||||||
@@ -373,7 +371,6 @@ int btSequentialImpulseConstraintSolverMt::getOrInitSolverBodyThreadsafe(btColli
|
|||||||
if ( INVALID_SOLVER_BODY_ID == solverBodyId )
|
if ( INVALID_SOLVER_BODY_ID == solverBodyId )
|
||||||
{
|
{
|
||||||
// create a table entry for this body
|
// create a table entry for this body
|
||||||
btRigidBody* rb = btRigidBody::upcast( &body );
|
|
||||||
solverBodyId = m_tmpSolverBodyPool.size();
|
solverBodyId = m_tmpSolverBodyPool.size();
|
||||||
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
btSolverBody& solverBody = m_tmpSolverBodyPool.expand();
|
||||||
initSolverBody( &solverBody, &body, timeStep );
|
initSolverBody( &solverBody, &body, timeStep );
|
||||||
@@ -400,7 +397,7 @@ int btSequentialImpulseConstraintSolverMt::getOrInitSolverBodyThreadsafe(btColli
|
|||||||
}
|
}
|
||||||
solverBodyId = m_fixedBodyId;
|
solverBodyId = m_fixedBodyId;
|
||||||
}
|
}
|
||||||
btAssert( solverBodyId < m_tmpSolverBodyPool.size() );
|
btAssert( solverBodyId >= 0 && solverBodyId < m_tmpSolverBodyPool.size() );
|
||||||
return solverBodyId;
|
return solverBodyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user