"ArithmeticException: This matrix cannot be inverted" when using collideWith

Running through the exercise at the end of chapter 3 of the JME3 book.

I tried to compute my collisions by using collideWith() (no real physics; just using the meshes). Every Geometry so far is a “Box”. Made a semi-transparent box around the towers, and check if the creeps enter it, but then I get this:

Creep1 BB: BoundingBox [Center: (5.0, 1.0, 4.816025) xExtent: 0.5 yExtent: 0.5 zExtent: 0.5]
TOWER_PROPER BB: BoundingBox [Center: (0.0, 0.0, 0.0) xExtent: 1.0 yExtent: 3.5 zExtent: 1.0]

java.lang.ArithmeticException: This matrix cannot be inverted
at com.jme3.math.Matrix4f.invert(Matrix4f.java:1474)
at com.jme3.math.Matrix4f.invert(Matrix4f.java:1446)
at com.jme3.collision.bih.BIHTree.collideWithBoundingVolume(BIHTree.java:445)
at com.jme3.collision.bih.BIHTree.collideWith(BIHTree.java:459)
at com.jme3.scene.Mesh.collideWith(Mesh.java:908)
at com.jme3.scene.Geometry.collideWith(Geometry.java:408)
at mygame.CreepControl.updateAlive(CreepControl.java:57)

I read somewhere that this happens if the boxes are too small, but as the output shows, the boxes are not small. So it must be something else.

Also, I am having strange trouble with the BoundingVolume anyway.

When I call Geometry.getModelBound(), the BoundingVolume does not have it’s center set, I have to do: bb.setCenter(spatial.getWorldTranslation()) every time.

And the BoundingVolume also only represent the initial Box creation size; the extents do no take scaling into account, so I cannot use scaling on the boxes.

What am I doing wrong?

Actually, I found the method “getWorldBound()”, which seems to solve the getWorldTranslation() issue (I haven’t check the scaling, but assume it is now fixed). Unfortunately, I still get the same exception.

bounds should be updated when you transform a geometry.
Show your code it might be a lot more helpful than describing the actual issue.

OK, solved it:

First I do this:

final BoundingBox bb = (BoundingBox) ((Geometry) spatial).getWorldBound();
// …
Then
if (((BoundingBox) child.getWorldBound()).intersectsBoundingBox(bb)) {
// …

Edit: The problem with the center was that I used the wrong “getter” to get the BoundingBox. I must use getWorldBound() instead of getModelBound().