PhysicsSpace collisionListeners "to array" (concurrent access linked list)


I was having a trouble, I was creating a rigid body and adding a collision listener while the collision() was happening (on that code), causing concurrent linked list access;

I did this change that fixed it here:


Index: src/jbullet/com/jme3/bullet/


— src/jbullet/com/jme3/bullet/ (revision 7793)

+++ src/jbullet/com/jme3/bullet/ (working copy)

@@ -347,7 +347,7 @@

synchronized (collisionEvents) {

for (Iterator<PhysicsCollisionEvent> it = collisionEvents.iterator(); it.hasNext():wink: {

PhysicsCollisionEvent physicsCollisionEvent =;

  •            for (PhysicsCollisionListener listener : collisionListeners) {<br />
  •            for (PhysicsCollisionListener listener : collisionListeners.toArray(new PhysicsCollisionListener[]{})) {<br />



//recycle events


I just wonder if it is ok or if I should avoid doing that on that thread? may be create the other rigid body later?

Yeah, enqueue the generation:

[snippet id=“10”]

1 Like

ok, I put all add and remove physics on my queue implementation, and it worked without errors, but my app got slow… I will try the enqueue() to see what happens, thx!

Still waiting for Paul’s SafeArrayList :wink: