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

Hi!



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:



[patch]

Index: src/jbullet/com/jme3/bullet/PhysicsSpace.java

===================================================================

— src/jbullet/com/jme3/bullet/PhysicsSpace.java (revision 7793)

+++ src/jbullet/com/jme3/bullet/PhysicsSpace.java (working copy)

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

synchronized (collisionEvents) {

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

PhysicsCollisionEvent physicsCollisionEvent = it.next();

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

listener.collision(physicsCollisionEvent);

}

//recycle events

[/patch]



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: