Exception: Removing object from physicsspace (Solved)

I think your familiar with this

[java]

18.03.2011 12:06:30 com.jme3.app.Application handleError

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

java.util.ConcurrentModificationException

at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:761)

at java.util.LinkedList$ListItr.next(LinkedList.java:696)

at com.jme3.bullet.PhysicsSpace.distributeEvents(PhysicsSpace.java:349)

at com.jme3.bullet.BulletAppState.update(BulletAppState.java:177)

at com.jme3.app.state.AppStateManager.update(AppStateManager.java:143)

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

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

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

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

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

[/java]





The problem occurs while i am trying to remove an object (which implements PhysicsCollisionListener and is an extension of PhysicsCollisionObject) on its PhysicsCollisionEvent from the physicsspace.

The same problem occurs if i remove the physicsCollisionListener from the physicsspace when it gets notified about a collision.



Why is this exception thrown?

Because you cannot do that ^^

When the collision happens the physics space is updated and you should not modify it. Its like the render() update for graphics. So just enqueue the removing like you would when you are on another thread, then its removed before the next update.

1 Like

Thx.Whats the best way to do that enqueuing? :slight_smile: (i have little thread-safety knowledge)



In my case, im just setting a flag; the update method checks for the flag and if true, does the removing. As far as i know the update method is the holy grail of thread safety :slight_smile:

Yeah, thats fine, you could also do it like this (minus the get, it would cause a deadlock):

[snippet id=“10”]

1 Like

Thx, topic solved