diff --git a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp index eed947a60..93206b2b2 100644 --- a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp +++ b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp @@ -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;im_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); diff --git a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h index 1cf3fe93f..ee57c2e2e 100644 --- a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h +++ b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h @@ -77,6 +77,8 @@ protected: btAlignedObjectArray m_indexArrays; btAlignedObjectArray m_shortIndexArrays; + btAlignedObjectArray m_charIndexArrays; + btAlignedObjectArray m_floatVertexArrays; btAlignedObjectArray m_doubleVertexArrays; diff --git a/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp b/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp index bc2f9f214..dd22fc563 100644 --- a/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp +++ b/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp @@ -253,9 +253,11 @@ const char* btStridingMeshInterface::serialize(void* dataBuffer, btSerializer* s memPtr->m_indices16 = 0; memPtr->m_indices32 = 0; memPtr->m_3indices16 = 0; + memPtr->m_3indices8 = 0; memPtr->m_vertices3f = 0; memPtr->m_vertices3d = 0; + switch (gfxindextype) { case PHY_INTEGER: