From 1ae6e98d05cb5dc4438e976a39dc3f45dac62486 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Mon, 6 Feb 2017 12:01:44 +0100 Subject: [PATCH] Fix MeshCollisionShape crash when loaded from j3o: always create BVH before scaling. --- .../collision/shapes/MeshCollisionShape.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/MeshCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/MeshCollisionShape.java index 9f36d28a81..3c5dbbb495 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/MeshCollisionShape.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/MeshCollisionShape.java @@ -122,7 +122,7 @@ public MeshCollisionShape(ByteBuffer indices, ByteBuffer vertices, boolean memor this.vertexStride = 12; this.triangleIndexStride = 12; this.memoryOptimized = memoryOptimized; - this.createShape(true); + this.createShape(null); } private void createCollisionMesh(Mesh mesh) { @@ -150,7 +150,7 @@ private void createCollisionMesh(Mesh mesh) { vertices.rewind(); vertices.clear(); - this.createShape(true); + this.createShape(null); } @Override @@ -191,25 +191,19 @@ public void read(final JmeImporter im) throws IOException { this.vertexBase = BufferUtils.createByteBuffer(capsule.readByteArray(MeshCollisionShape.VERTEX_BASE, null)); byte[] nativeBvh = capsule.readByteArray(MeshCollisionShape.NATIVE_BVH, null); - if (nativeBvh == null) { - // Either using non memory optimized BVH or old J3O file - memoryOptimized = false; - createShape(true); - } else { - // Using memory optimized BVH, load from J3O, then assign it. - memoryOptimized = true; - createShape(false); - nativeBVHBuffer = setBVH(nativeBvh, this.objectId); - } + memoryOptimized=nativeBvh != null; + createShape(nativeBvh); } - private void createShape(boolean buildBvt) { + private void createShape(byte bvh[]) { + boolean buildBvh=bvh==null||bvh.length==0; this.meshId = NativeMeshUtil.createTriangleIndexVertexArray(this.triangleIndexBase, this.vertexBase, this.numTriangles, this.numVertices, this.vertexStride, this.triangleIndexStride); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Mesh {0}", Long.toHexString(this.meshId)); - this.objectId = createShape(memoryOptimized, buildBvt, this.meshId); + this.objectId = createShape(memoryOptimized, buildBvh, this.meshId); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(this.objectId)); + if(!buildBvh) nativeBVHBuffer = setBVH(bvh, this.objectId); this.setScale(this.scale); - this.setMargin(this.margin); + this.setMargin(this.margin); } /**