BulletWorldImporter didn't properly import m_3indices16 arrays, fixes Issue 562 thanks to Marius Elvert

Support for m_3indices8 import
Fix un-initialized memPtr->m_3indices8 at export time, add a workaround at loading time
This commit is contained in:
erwin.coumans
2011-11-15 18:40:45 +00:00
parent f64fc0a26b
commit d3c6f9dd67
3 changed files with 51 additions and 5 deletions

View File

@@ -94,6 +94,10 @@ void btBulletWorldImporter::deleteAllData()
if(curPart->m_indices16)
delete [] curPart->m_indices16;
if (curPart->m_3indices8)
delete [] curPart->m_3indices8;
}
delete [] curData->m_meshPartsPtr;
delete curData;
@@ -108,8 +112,13 @@ void btBulletWorldImporter::deleteAllData()
for (i=0;i<m_shortIndexArrays.size();i++)
{
btAlignedFree(m_shortIndexArrays[i]);
}
for (i=0;i<m_charIndexArrays.size();i++)
{
btAlignedFree(m_charIndexArrays[i]);
}
for (i=0;i<m_floatVertexArrays.size();i++)
{
btAlignedFree(m_floatVertexArrays[i]);
@@ -173,9 +182,9 @@ btTriangleIndexVertexArray* btBulletWorldImporter::createMeshInterface(btStridin
meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
} else
{
meshPart.m_indexType = PHY_SHORT;
if (meshData.m_meshPartsPtr[i].m_3indices16)
{
meshPart.m_indexType = PHY_SHORT;
meshPart.m_triangleIndexStride = sizeof(short int)*3;//sizeof(btShortIntIndexTripletData);
short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int)*3*meshPart.m_numTriangles,16);
@@ -192,6 +201,7 @@ btTriangleIndexVertexArray* btBulletWorldImporter::createMeshInterface(btStridin
}
if (meshData.m_meshPartsPtr[i].m_indices16)
{
meshPart.m_indexType = PHY_SHORT;
meshPart.m_triangleIndexStride = 3*sizeof(short int);
short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int)*3*meshPart.m_numTriangles,16);
m_shortIndexArrays.push_back(indexArray);
@@ -203,6 +213,23 @@ btTriangleIndexVertexArray* btBulletWorldImporter::createMeshInterface(btStridin
meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
}
if (meshData.m_meshPartsPtr[i].m_3indices8)
{
meshPart.m_indexType = PHY_UCHAR;
meshPart.m_triangleIndexStride = sizeof(unsigned char)*3;
unsigned char* indexArray = (unsigned char*)btAlignedAlloc(sizeof(unsigned char)*3*meshPart.m_numTriangles,16);
m_charIndexArrays.push_back(indexArray);
for (int j=0;j<meshPart.m_numTriangles;j++)
{
indexArray[3*j] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[0];
indexArray[3*j+1] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[1];
indexArray[3*j+2] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[2];
}
meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
}
}
if (meshData.m_meshPartsPtr[i].m_vertices3f)
@@ -265,7 +292,7 @@ btStridingMeshInterfaceData* btBulletWorldImporter::createStridingMeshInterfaceD
curNewPart->m_numTriangles = curPart->m_numTriangles;
curNewPart->m_numVertices = curPart->m_numVertices;
if(curPart->m_vertices3f)
{
curNewPart->m_vertices3f = new btVector3FloatData[curNewPart->m_numVertices];
@@ -283,9 +310,13 @@ btStridingMeshInterfaceData* btBulletWorldImporter::createStridingMeshInterfaceD
curNewPart->m_vertices3d = NULL;
int numIndices = curNewPart->m_numTriangles * 3;
///the m_3indices8 was not initialized in some Bullet versions, this can cause crashes at loading time
///we catch it by only dealing with m_3indices8 if none of the other indices are initialized
bool uninitialized3indices8Workaround =false;
if(curPart->m_indices32)
{
uninitialized3indices8Workaround=true;
curNewPart->m_indices32 = new btIntIndexData[numIndices];
memcpy(curNewPart->m_indices32,curPart->m_indices32,sizeof(btIntIndexData) * numIndices);
}
@@ -294,19 +325,30 @@ btStridingMeshInterfaceData* btBulletWorldImporter::createStridingMeshInterfaceD
if(curPart->m_3indices16)
{
curNewPart->m_3indices16 = new btShortIntIndexTripletData[numIndices];
memcpy(curNewPart->m_3indices16,curPart->m_3indices16,sizeof(btShortIntIndexTripletData) * numIndices);
uninitialized3indices8Workaround=true;
curNewPart->m_3indices16 = new btShortIntIndexTripletData[curNewPart->m_numTriangles];
memcpy(curNewPart->m_3indices16,curPart->m_3indices16,sizeof(btShortIntIndexTripletData) * curNewPart->m_numTriangles);
}
else
curNewPart->m_3indices16 = NULL;
if(curPart->m_indices16)
{
uninitialized3indices8Workaround=true;
curNewPart->m_indices16 = new btShortIntIndexData[numIndices];
memcpy(curNewPart->m_indices16,curPart->m_indices16,sizeof(btShortIntIndexData) * numIndices);
}
else
curNewPart->m_indices16 = NULL;
if(!uninitialized3indices8Workaround && curPart->m_3indices8)
{
curNewPart->m_3indices8 = new btCharIndexTripletData[curNewPart->m_numTriangles];
memcpy(curNewPart->m_3indices8,curPart->m_3indices8,sizeof(btCharIndexTripletData) * curNewPart->m_numTriangles);
}
else
curNewPart->m_3indices8 = NULL;
}
m_allocatedbtStridingMeshInterfaceDatas.push_back(newData);