From 6446c7c302007ae9d95740097022526157b4380f Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 18 Aug 2016 11:49:15 -0700 Subject: [PATCH] make createShapeFromInfo() fail gently on bad data --- libraries/physics/src/ShapeFactory.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/libraries/physics/src/ShapeFactory.cpp b/libraries/physics/src/ShapeFactory.cpp index 137038e133..5182038c27 100644 --- a/libraries/physics/src/ShapeFactory.cpp +++ b/libraries/physics/src/ShapeFactory.cpp @@ -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; }