@normen can you confirm this?
Well I have a crash with
java.lang.NullPointerException: The vehicle object does not exist.
at com.jme3.bullet.PhysicsSpace.addVehicle(Native Method)
at com.jme3.bullet.PhysicsSpace.addRigidBody(PhysicsSpace.java:638)
at com.jme3.bullet.PhysicsSpace.addCollisionObject(PhysicsSpace.java:423)
…
And I think the cause is a update/rebuild error in the physic vehicles, or I understand some part of the concept false.
I create a PhysicVehicle with
rbody = new PhysicsVehicle(shape, pobj.getMass());
this.physicspace.addCollisionObject(rbody);
Now what happens, the constructor calls rebuildRigidBody
This calls postRebuild()
this in the Vehicle subclass should create the native Vehicle if it does not exist, but only if a physicspace does already exist (it does not as it is still in the initial constructor call at this point, so no vehicle is created here at this time)
[java]
if (space == null) {
return;
}
[/java]
Then I add it to the Physicspace, this goes to private void addRigidBody(PhysicsRigidBody node)
here it is tested if it represents a Vehicle
[java]
if (node instanceof PhysicsVehicle) {
logger.log(Level.FINE, “Adding vehicle constraint {0} to physics space.”, Long.toHexString(((PhysicsVehicle) node).getVehicleId()));
physicsVehicles.put(((PhysicsVehicle) node).getVehicleId(), (PhysicsVehicle) node);
addVehicle(physicsSpaceId, ((PhysicsVehicle) node).getVehicleId());
[/java]
At this point the vehicleid is tried to be used, however since no other attempt to rebuild happened, it is 0 here leading to the exception above.
I think the solution would be to check for the vehicle and do a rebuild it none exist.
Can anyone confirm this finding? If so I will attempt to patch this and post the diff.
This little hack does represent a dirty workaround, that simple sets the correct Physicspace and retries to create that vehicle object
[java]
if (node instanceof PhysicsVehicle) {
final PhysicsVehicle vehicle = (PhysicsVehicle) node;
vehicle.physicsSpace = this;
vehicle.postRebuild();
PhysicsSpace.logger.log(Level.FINE, “Adding vehicle constraint {0} to physics space.”, Long.toHexString(((PhysicsVehicle) node).getVehicleId()));
this.physicsVehicles.put(vehicle.getVehicleId(), vehicle);
this.addVehicle(this.physicsSpaceId, vehicle.getVehicleId());
}
[/java]