Bullet throws a NPE

Hello,

i am currently rewriteing my ball game to use bullet.

I also introduced some new elements, one of these new elements causes a NPE which i cannot explain.

Here is the code which causes the NPE:

[java]

public abstract class BlockControl extends AbstractControl {



float height = 0;

float current = 0;

float speed = 1;



@Override

protected void controlUpdate(float tpf) {

if (this.speed != 0) {

current = current + (speed * tpf);

height = (float) Math.sin(current);



Vector3f loc = this.spatial.getLocalTranslation();

loc.y = (float) (this.height1.5);

this.spatial.setLocalTranslation(loc);

}

}



@Override

protected void controlRender(RenderManager rm, ViewPort vp) {

}



public void setSpeed(float f) {

this.speed = f;

}



abstract public Control cloneForSpatial(Spatial spatial);



abstract void onHit(PlayerControl player);



abstract boolean isSolid();

}

[/java]



Note the line:

[java]loc.y=(float) (this.height
1.5);[/java]

because changing the code to:

[java]loc.y=(float) (this.height0.5);[/java]

makes the program work without issue. But a movement of height
1.5 :frowning:



Additionally here is the error stack:

[java]

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:119)

at com.bulletphysics.collision.dispatch.CompoundCollisionAlgorithm.destroy(CompoundCollisionAlgorithm.java:76)

at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:120)

at com.bulletphysics.collision.dispatch.CompoundCollisionAlgorithm.destroy(CompoundCollisionAlgorithm.java:76)

at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:120)

at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.cleanOverlappingPair(HashedOverlappingPairCache.java:219)

at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.removeOverlappingPair(HashedOverlappingPairCache.java:91)

at com.bulletphysics.collision.broadphase.DbvtBroadphase.collide(DbvtBroadphase.java:145)

at com.bulletphysics.collision.broadphase.DbvtBroadphase.calculateOverlappingPairs(DbvtBroadphase.java:235)

at com.bulletphysics.collision.dispatch.CollisionWorld.performDiscreteCollisionDetection(CollisionWorld.java:139)

at com.bulletphysics.dynamics.DiscreteDynamicsWorld.internalSingleStepSimulation(DiscreteDynamicsWorld.java:378)

at com.bulletphysics.dynamics.DiscreteDynamicsWorld.stepSimulation(DiscreteDynamicsWorld.java:339)

at com.jme3.bullet.PhysicsSpace.update(PhysicsSpace.java:324)

at com.jme3.bullet.PhysicsSpace.update(PhysicsSpace.java:311)

at com.jme3.bullet.BulletAppState.render(BulletAppState.java:185)

at com.jme3.app.state.AppStateManager.render(AppStateManager.java:262)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:722)

[/java]



I hope somebody can help me with this

Make sure you didn’t add or remove a physics object twice to/from the physicsspace

hm. if i deepClone() an object with added GhostControl() and add both to physics, would this count as adding a object twice?

Uh no, they are just sharing their collision shape but given that you do such stuff, its easy to make a mistake and remove or add something twice somewhere, had that a few times now.

@normen said:
Uh no, they are just sharing their collision shape but given that you do such stuff, its easy to make a mistake and remove or add something twice somewhere, had that a few times now.


Would in that case bullet not crash independently of the height modificator?

If you want internal information on bullet, check it source or ask its developers, I know I got this error when I removed a RigidBody twice. And not immediately but when the next physics update runs and certain objects overlap.

I finally found the ‘bug’ which caused the problem.

After reading the doc found here: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics

i assume that collisions between two mesh based collision shapes are not a problem but they are not going to be detected.



So i made level out of mesh based collision shapes. The touch each other at the endings. This all was not a problem, but as soon as they do not overlap anymore the physics threw the NPE.

When changing all models to a BoxCollisionShape the error was gone.



So eighter the doc is outdated/missleading or i understand that wrong :frowning:

Why would mesh shapes suddenly not overlap anymore? They are supposed to be used only with static objects, I guess you have something else going wrong.

Because i used them for a block which act as an elevator.



Add: changing the elevator to a HullCollisionShape solved the problem completele and does give me the same Shape as MeshBased. Shame on my to not fully read the doc ;(

Movable but not affected by physics = kinematic object, and moving mesh shapes will not produce correct results, use Hull shapes or if absolutely necessary GImpact shapes.