Some ClassCastException

(Similar to an earlier physics troubleshooting post I posted, but different exception.)
I get this exception only sometimes:
[java]
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,10,main]
java.lang.ClassCastException: com.bulletphysics.collision.shapes.BvhTriangleMeshShape cannot be cast to com.bulletphysics.collision.shapes.CompoundShape
at com.bulletphysics.collision.dispatch.CompoundCollisionAlgorithm.processCollision(CompoundCollisionAlgorithm.java:87)
at com.bulletphysics.collision.dispatch.DefaultNearCallback.handleCollision(DefaultNearCallback.java:55)
at com.bulletphysics.collision.dispatch.CollisionDispatcher$CollisionPairCallback.processOverlap(CollisionDispatcher.java:236)
at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.processAllOverlappingPairs(HashedOverlappingPairCache.java:190)
at com.bulletphysics.collision.dispatch.CollisionDispatcher.dispatchAllCollisionPairs(CollisionDispatcher.java:247)
at com.bulletphysics.dynamics.character.KinematicCharacterController.recoverFromPenetration(KinematicCharacterController.java:376)
at com.bulletphysics.dynamics.character.KinematicCharacterController.preStep(KinematicCharacterController.java:200)
at com.bulletphysics.dynamics.character.KinematicCharacterController.updateAction(KinematicCharacterController.java:143)
at com.bulletphysics.dynamics.DiscreteDynamicsWorld.updateActions(DiscreteDynamicsWorld.java:461)
at com.bulletphysics.dynamics.DiscreteDynamicsWorld.internalSingleStepSimulation(DiscreteDynamicsWorld.java:393)
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:212)
at com.jme3.app.state.AppStateManager.render(AppStateManager.java:274)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:251)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:662)
[/java]
Any idea why before I might dive into the source code?

Seems to be some issue you have when assigning collision shapes. Do you create them on multiple other threads? Jbullet seems to have issues with that.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless theres emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

@normen said: Seems to be some issue you have when assigning collision shapes. Do you create them on multiple other threads? Jbullet seems to have issues with that.
@normen That's actually exactly what I do :-o I use [java]scheduledThreadPoolExecutor.submit(callable)[/java] which contains lines that create new collision shapes. I do this partially because when I created new physics objects within simpleUpdate() and profiled my project, I saw that it took quite some time to build a new collision shape, which happens often in my game. I don't remember if it was enough to severely drop FPS, but I changed it so that multithreading took care of it. So I guess I should go back to creating new physics objects within simpleUpdate()?

Just make sure its always the same thread and that they are not created in parallel. So the creating can be offloaded to some Executor but it should not create multiple shapes at once.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless theres emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

@normen 1. Would submitting a Callable that has a while(true) loop that never returns and creates the physics objects work? Or does that still count as creating on multiple threads? Because I assume that submitting 1 callable uses 1 thread.
2. Would a ScheduledThreadPoolExecutor with 1 core (so using “new ScheduledThreadPoolExecutor(1)”) work?

To be honest in a situation like this I’d just spawn a thread rather than using an executor. What you want is one controlled and constant thread doing the creation. I approve of executors generally but I don’t think they apply in this case.

(I’d use something like a threadsafe queue, spawn a single thread listening on that queue. Whenever anything gets added to the queue it wakes the thread which processes everything in the queue sequentially then goes back to sleep waiting for something to be added to be processed.

Make sure you don’t hold a lock on the queue while processing.

…or use a ThreadPoolExecutor… which is designed exactly for that kind of thing.

I just set the single static method that creates the meshes to synchronized , that should hopefully avoid issues in all cases. Afaik the issue is mainly in parallel creation of buffers and not in any actual thread discrepancies.
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.