Skip to content

Commit 2761bc3

Browse files
Merge pull request #615 from riccardobl/FixMeshCollisionShapeJ3oReadv3.1
Fix bullet crash when MeshCollisionShape is loaded from j3o [v3.1]
2 parents 69cd160 + 1ae6e98 commit 2761bc3

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/MeshCollisionShape.java

+9-15
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public MeshCollisionShape(ByteBuffer indices, ByteBuffer vertices, boolean memor
122122
this.vertexStride = 12;
123123
this.triangleIndexStride = 12;
124124
this.memoryOptimized = memoryOptimized;
125-
this.createShape(true);
125+
this.createShape(null);
126126
}
127127

128128
private void createCollisionMesh(Mesh mesh) {
@@ -150,7 +150,7 @@ private void createCollisionMesh(Mesh mesh) {
150150
vertices.rewind();
151151
vertices.clear();
152152

153-
this.createShape(true);
153+
this.createShape(null);
154154
}
155155

156156
@Override
@@ -191,25 +191,19 @@ public void read(final JmeImporter im) throws IOException {
191191
this.vertexBase = BufferUtils.createByteBuffer(capsule.readByteArray(MeshCollisionShape.VERTEX_BASE, null));
192192

193193
byte[] nativeBvh = capsule.readByteArray(MeshCollisionShape.NATIVE_BVH, null);
194-
if (nativeBvh == null) {
195-
// Either using non memory optimized BVH or old J3O file
196-
memoryOptimized = false;
197-
createShape(true);
198-
} else {
199-
// Using memory optimized BVH, load from J3O, then assign it.
200-
memoryOptimized = true;
201-
createShape(false);
202-
nativeBVHBuffer = setBVH(nativeBvh, this.objectId);
203-
}
194+
memoryOptimized=nativeBvh != null;
195+
createShape(nativeBvh);
204196
}
205197

206-
private void createShape(boolean buildBvt) {
198+
private void createShape(byte bvh[]) {
199+
boolean buildBvh=bvh==null||bvh.length==0;
207200
this.meshId = NativeMeshUtil.createTriangleIndexVertexArray(this.triangleIndexBase, this.vertexBase, this.numTriangles, this.numVertices, this.vertexStride, this.triangleIndexStride);
208201
Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Mesh {0}", Long.toHexString(this.meshId));
209-
this.objectId = createShape(memoryOptimized, buildBvt, this.meshId);
202+
this.objectId = createShape(memoryOptimized, buildBvh, this.meshId);
210203
Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(this.objectId));
204+
if(!buildBvh) nativeBVHBuffer = setBVH(bvh, this.objectId);
211205
this.setScale(this.scale);
212-
this.setMargin(this.margin);
206+
this.setMargin(this.margin);
213207
}
214208

215209
/**

0 commit comments

Comments
 (0)