Initialize and add rigid bodies from different thread

bearsomg
Posts: 5
Joined: Sat Jul 21, 2012 2:48 pm

Initialize and add rigid bodies from different thread

Post by bearsomg »

I am currently in the process of developing a realtime rendering engine. Part of the requirement for this is to have all character animation data and models loaded before they are used, which I have accomplished by using a worker thread to load and parse the files while the previous models and animations are being rendered in realtime. In this worker thread the model parsers are also initializing the rigid bodies of that model and adding them to the world. I noticed that when doing this, bullet will randomly cause crashes - I've noticed them happen during initialization, adding to world, and removing them when the program closes.

Figuring that this was the result of calling stepSimulation() from the main thread while another thread is initializing rigid bodies and adding them to the world, I made it so that the main thread would lock while the loader thread is running, and these issues stopped occurring altogether. From these results, I'm assuming that when a rigid body is added to the world at the same time stepSimulation() is called it causes a memory corruption which would result in the random crashes. Is this what is actually occurring, or is there some other issue within Bullet causing this that I'm not aware of? What would be the best and simplest way to change the code to work with multiple threads?