Fix for use of uninitialized variables.

m_implicitShapeDimensions was used in setMargin, called from setSafeMargin
from constructors of btBoxShape, btCylinerShape and btBox2dShape,
effectively using uninitialized variable and leading to floating point
exceptions.
It was working correctly only because in the same constructor
m_implicitShapeDimensions was reinitialized after setSafeMargin.
Properly initialize variable before use by first setting it up and only
then using it in setSafeMargin.
This commit is contained in:
AlexanderPolyakov
2014-10-07 19:10:35 +04:00
parent 46bd05f4f7
commit b7699024e2
3 changed files with 7 additions and 5 deletions

View File

@@ -103,11 +103,12 @@ public:
btScalar minDimension = boxHalfExtents.getX();
if (minDimension>boxHalfExtents.getY())
minDimension = boxHalfExtents.getY();
setSafeMargin(minDimension);
m_shapeType = BOX_2D_SHAPE_PROXYTYPE;
btVector3 margin(getMargin(),getMargin(),getMargin());
m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin;
setSafeMargin(minDimension);
};
virtual void setMargin(btScalar collisionMargin)

View File

@@ -19,10 +19,10 @@ btBoxShape::btBoxShape( const btVector3& boxHalfExtents)
{
m_shapeType = BOX_SHAPE_PROXYTYPE;
setSafeMargin(boxHalfExtents);
btVector3 margin(getMargin(),getMargin(),getMargin());
m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin;
setSafeMargin(boxHalfExtents);
};

View File

@@ -19,10 +19,11 @@ btCylinderShape::btCylinderShape (const btVector3& halfExtents)
:btConvexInternalShape(),
m_upAxis(1)
{
setSafeMargin(halfExtents);
btVector3 margin(getMargin(),getMargin(),getMargin());
m_implicitShapeDimensions = (halfExtents * m_localScaling) - margin;
setSafeMargin(halfExtents);
m_shapeType = CYLINDER_SHAPE_PROXYTYPE;
}