diff --git a/MinieLibrary/src/main/java/com/jme3/bullet/collision/shapes/GImpactCollisionShape.java b/MinieLibrary/src/main/java/com/jme3/bullet/collision/shapes/GImpactCollisionShape.java index b96836c6d..d1bb8723a 100644 --- a/MinieLibrary/src/main/java/com/jme3/bullet/collision/shapes/GImpactCollisionShape.java +++ b/MinieLibrary/src/main/java/com/jme3/bullet/collision/shapes/GImpactCollisionShape.java @@ -87,11 +87,14 @@ protected GImpactCollisionShape() { /** * Instantiate a shape based on the specified CompoundMesh and offset. * - * @param mesh the mesh on which to base the shape (not null, unaffected) + * @param mesh the mesh on which to base the shape (not null, must contain + * at least one triangle, unaffected) * @param offset the offset to add to the vertex positions (not null, * unaffected) */ public GImpactCollisionShape(CompoundMesh mesh, Vector3f offset) { + Validate.require(mesh.countTriangles() > 0, "at least one triangle"); + this.nativeMesh = new CompoundMesh(mesh, offset); createShape(); } @@ -99,24 +102,31 @@ public GImpactCollisionShape(CompoundMesh mesh, Vector3f offset) { /** * Instantiate a shape based on the specified native mesh(es). * - * @param submeshes the mesh(es) on which to base the shape (not null) + * @param submeshes the mesh(es) on which to base the shape (not null, must + * contain at least one triangle) */ public GImpactCollisionShape(IndexedMesh... submeshes) { this.nativeMesh = new CompoundMesh(); for (IndexedMesh submesh : submeshes) { nativeMesh.add(submesh); } + Validate.require( + nativeMesh.countTriangles() > 0, "at least one triangle"); + createShape(); } /** * Instantiate a shape based on the specified JME mesh(es). * - * @param jmeMeshes the mesh(es) on which to base the shape (not null, - * unaffected) + * @param jmeMeshes the mesh(es) on which to base the shape (not null, must + * contain at least one triangle, unaffected) */ public GImpactCollisionShape(Mesh... jmeMeshes) { this.nativeMesh = new CompoundMesh(jmeMeshes); + Validate.require( + nativeMesh.countTriangles() > 0, "at least one triangle"); + createShape(); } // ************************************************************************* @@ -303,6 +313,9 @@ public void write(JmeExporter exporter) throws IOException { * Instantiate the configured {@code btGImpactMeshShape}. */ private void createShape() { + int numTriangles = nativeMesh.countTriangles(); + assert numTriangles > 0 : numTriangles; + long meshId = nativeMesh.nativeId(); long shapeId = createShape(meshId); setNativeId(shapeId); diff --git a/MinieLibrary/src/test/java/jme3utilities/minie/test/TestEmptyShape.java b/MinieLibrary/src/test/java/jme3utilities/minie/test/TestEmptyShape.java index 109eecb52..b66761bbe 100644 --- a/MinieLibrary/src/test/java/jme3utilities/minie/test/TestEmptyShape.java +++ b/MinieLibrary/src/test/java/jme3utilities/minie/test/TestEmptyShape.java @@ -95,13 +95,21 @@ public void testEmptyShape() { shape = new CompoundCollisionShape(); rigidBody = new PhysicsRigidBody(shape, PhysicsBody.massForStatic); - shape = new GImpactCollisionShape(indexedMeshArray); - rigidBody = new PhysicsRigidBody(shape, PhysicsBody.massForStatic); + // Attempt to create empty shapes in various illegal ways. + try { + shape = new GImpactCollisionShape(indexedMeshArray); + Assert.fail("Expected an IllegalArgumentException"); + } catch (IllegalArgumentException exception) { + // do nothing + } - shape = new GImpactCollisionShape(jmeMeshArray); - rigidBody = new PhysicsRigidBody(shape, PhysicsBody.massForStatic); + try { + shape = new GImpactCollisionShape(jmeMeshArray); + Assert.fail("Expected an IllegalArgumentException"); + } catch (IllegalArgumentException exception) { + // do nothing + } - // Attempt to create empty shapes in various illegal ways. try { shape = new HeightfieldCollisionShape(floatArray); Assert.fail("Expected an IllegalArgumentException");