Multithreading Troubles

I’m having some trouble with multithreading. So I have set up multithreading on my application and it works fine for my generation method. In another section in my code I use multithreading to attach thing to bullet’s physic space. I’m getting some concurrency issues with that. How do I / should I run things in the main thread from a different thread.


You cannot change the state of the scene during rendering. That is any where outside the update loop. As Empire pointed out the you can implement a Callable and enqueue it on your SimpleApplication via .enqueue(). It will get executed as the first thing in the update loop ( just before .simpleUpdate( tpf ) is called. ).

On another note I have implemented a “ConcurrentPositionControl”, to deal with concurrency issues, it simply writes a concurrent position into the local position during the Controls update(). ( I did this since my position is updating more than once per frame, and I wanted to avoid enqueing or tracking multpile callables for the position of the same spatial. My guess is that .enqueue() will be a better solution in your case though, but there are many ways to address it - most important is that it occurs in the update() loop.

PhysicsSpace has an enqueue method as well, though, I have no idea if this should be called directly or not.

I experienced problems enqueue add/remove calls to the physics space via the application. No clue why that is either.