[Bug Report] Uninitialized values

marshall
Posts: 7
Joined: Wed Jun 13, 2007 6:14 pm

[Bug Report] Uninitialized values

Post by marshall »

Hello. This is my first post here but in setting up a simple test I ran valgrind on
the code and found some potential issues. I apoligize in advanced if this is not the
correct forum for posting this.

The first is from the file
btPersistentManifold.h in the method
removeContactPoint()

There is a case when the index and lastUsedIndex can be the same, particularly
when the index is 0. This results in a "source-destination overlap in memcpy"
error in valgrind. Changing the code to:

if(index != lastUsedIndex) m_pointCache[index] = m_pointCache[lastUsedIndex];

Fixes the problem.


The next is in:
btVoronoiSimplexSolver.cpp in method
btVoronoiSimplexSolver::updateClosestVectorAndPoints()

for case 3 it says:

case 3:
{
//closest point origin from triangle
btVector3 p (btScalar(0.),btScalar(0.),btScalar(0.));

const btVector3& a = m_simplexVectorW[0];
const btVector3& b = m_simplexVectorW[1];
const btVector3& c = m_simplexVectorW[2];

closestPtPointTriangle(p,a,b,c,m_cachedBC);
m_cachedP1 = m_simplexPointsP[0] * m_cachedBC.m_barycentricCoords[0] +
m_simplexPointsP[1] * m_cachedBC.m_barycentricCoords[1] +
m_simplexPointsP[2] * m_cachedBC.m_barycentricCoords[2] +
m_simplexPointsP[3] * m_cachedBC.m_barycentricCoords[3];

m_cachedP2 = m_simplexPointsQ[0] * m_cachedBC.m_barycentricCoords[0] +
m_simplexPointsQ[1] * m_cachedBC.m_barycentricCoords[1] +
m_simplexPointsQ[2] * m_cachedBC.m_barycentricCoords[2] +
m_simplexPointsQ[3] * m_cachedBC.m_barycentricCoords[3];

m_cachedV = m_cachedP1-m_cachedP2;

reduceVertices (m_cachedBC.m_usedVertices);
m_cachedValidClosest = m_cachedBC.isValid();

break;
}

It's using the fourth simplex point however they don't exist. I believe this should be
changed to:

case 3:
{
//closest point origin from triangle
btVector3 p (btScalar(0.),btScalar(0.),btScalar(0.));

const btVector3& a = m_simplexVectorW[0];
const btVector3& b = m_simplexVectorW[1];
const btVector3& c = m_simplexVectorW[2];

closestPtPointTriangle(p,a,b,c,m_cachedBC);
m_cachedP1 = m_simplexPointsP[0] * m_cachedBC.m_barycentricCoords[0] +
m_simplexPointsP[1] * m_cachedBC.m_barycentricCoords[1] +
m_simplexPointsP[2] * m_cachedBC.m_barycentricCoords[2];

m_cachedP2 = m_simplexPointsQ[0] * m_cachedBC.m_barycentricCoords[0] +
m_simplexPointsQ[1] * m_cachedBC.m_barycentricCoords[1] +
m_simplexPointsQ[2] * m_cachedBC.m_barycentricCoords[2];

m_cachedV = m_cachedP1-m_cachedP2;

reduceVertices (m_cachedBC.m_usedVertices);
m_cachedValidClosest = m_cachedBC.isValid();

break;
}
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

This is the right location, issues, bugreports can be discussed here.

I verified both issues, and they have been fixed in Subversion, so they are scheduled for next release.

Thanks a lot for the fixes!
Erwin
slithEToves
Posts: 24
Joined: Mon Mar 12, 2007 9:55 pm

Post by slithEToves »

Thanks for the fixes. I was getting floating point exceptions previous to this change, but not anymore.