Multiple Worlds

DragonGeo2
Posts: 16
Joined: Sat Dec 18, 2010 1:30 am

Multiple Worlds

Post by DragonGeo2 »

Hello,

I'm experiencing a problem in Bullet, but I think it's related to something I'm doing and not really a bug in the library or anything. What I'm trying to do is take one btCollisionObject and add it into two different btCollisionWorlds. It's the same object with the same transform and the same geometry, so I figured I should use just one btCollisionObject for both. Why waste memory with two btCollisionObjects, right?

This actually works great for me until I try to remove the object from both worlds at a later time. Then what happens is that it removes from the first world fine, but then when I try to remove it from the second world, it either crashes (access violation) or ends up in an infinite loop in:
myCode::RemoveObjectFromSimulation()
btCollisionWorld::removeCollisionObject()
btDbvtBroadphase::destroyProxy()
HashedOverlappingPairsCache::removeOverlappingPairsContainingProxy()
HashedOverlappingPairsCache::processAllOverlappingPairs() <-- the for loop in here is never-ending because the proxy hash is messed up

So can someone tell me whether what I'm trying to do is wrong, and can someone else *please* tell me how to fix this in the least memory-intensive way possible?
shomy2k11
Posts: 24
Joined: Thu Sep 08, 2011 1:59 am

Re: Multiple Worlds

Post by shomy2k11 »

Hi,
have you made any progress with this?
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: Multiple Worlds

Post by Mako_energy02 »

The callstack says it all. A collision object can only have one collision proxy/broadphase handle at a time. When you go to create the object and add it to multiple worlds the internal structurals for each world have a workable proxy, so it appears to work. But once you go to manipulate anything on the object that uses the broadphase proxy (such as removing it from the world) it will only have one and can cause errors. In this case you are performing a double delete, which causes the error you get. Collision objects aren't meant to exist in two worlds at once.
shomy2k11
Posts: 24
Joined: Thu Sep 08, 2011 1:59 am

Re: Multiple Worlds

Post by shomy2k11 »

thanks bro...