make createShapeFromInfo() fail gently on bad data

This commit is contained in:
Andrew Meadows 2016-08-18 11:49:15 -07:00
parent 2ba35e6398
commit 6446c7c302

View file

@ -164,13 +164,24 @@ btTriangleIndexVertexArray* createStaticMeshArray(const ShapeInfo& info) {
assert(info.getType() == SHAPE_TYPE_STATIC_MESH); // should only get here for mesh shapes
const ShapeInfo::PointCollection& pointCollection = info.getPointCollection();
assert(pointCollection.size() == 1); // should only have one mesh
if (pointCollection.size() < 1) {
// no lists of points to work with
return nullptr;
}
// we only use the first point collection
const ShapeInfo::PointList& pointList = pointCollection[0];
assert(pointList.size() > 2); // should have at least one triangle's worth of points
if (pointList.size() < 3) {
// not enough distinct points to make a non-degenerate triangle
return nullptr;
}
const ShapeInfo::TriangleIndices& triangleIndices = info.getTriangleIndices();
assert(triangleIndices.size() > 2); // should have at least one triangle's worth of indices
if (triangleIndices.size() < 3) {
// not enough indices to make a single triangle
return nullptr;
}
// allocate mesh buffers
btIndexedMesh mesh;
@ -328,7 +339,9 @@ btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info) {
break;
case SHAPE_TYPE_STATIC_MESH: {
btTriangleIndexVertexArray* dataArray = createStaticMeshArray(info);
shape = new StaticMeshShape(dataArray);
if (dataArray) {
shape = new StaticMeshShape(dataArray);
}
}
break;
}