mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:24:07 +02:00
make createShapeFromInfo() fail gently on bad data
This commit is contained in:
parent
2ba35e6398
commit
6446c7c302
1 changed files with 17 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue