[Bullet 2.50b0] removeRigidBody & btAxisSweep3 bug

tbp
Posts: 4
Joined: Sat May 19, 2007 4:51 pm

[Bullet 2.50b0] removeRigidBody & btAxisSweep3 bug

Post by tbp »

Briefly, it seems that btAxisSweep3 is left in an inconsistent state once you remove a rigid body via the world interface.

With

Code: Select all

...
dispatcher	= new btCollisionDispatcher();
broadphase	= new btAxisSweep3(world_min, world_max, num_max_proxies);
solver		= new btSequentialImpulseConstraintSolver();
world		= new btDiscreteDynamicsWorld(dispatcher, broadphase, solver);
...
world->addRigidBody(body);
... later...
world->removeRigidBody(body);
i get an 'access violation' in 'void btAxisSweep3::sortMaxDown(int axis, BP_FP_INT_TYPE edge, bool updateOverlaps)' at line 547 once i add another rigid body and then step the simulation. If i swap the btAxisSweep3 broadphase for a btSimpleBroadphase, everything's fine.
I've searched around for such issue, read the doc & samples (which cannot trigger that bug as everything's cleaned at once) but came up with nothing.
It's not clear to me if what i'm doing is legit, so please forgive my ignorance :)
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

Can you create a reproducing case that shows the problem? Which platform/compiler do you use? Did you initialize the world transform for each rigidbody that was added?

So far, I haven't been able to reproduce this issue. When removing and adding rigidbodies in the CcdPhysicsDemo all works fine here.

Thanks a lot,
Erwin
tbp
Posts: 4
Joined: Sat May 19, 2007 4:51 pm

Post by tbp »

Win32, msvc8 sp1. I think i'm correctly initializing rigid body's world transform because i've mostly cut & pasted that code, those objects are correctly positioned and it's then properly extracted for display. I should have said i have a couple of btStaticPlaneShape and my rigid bodies are made of btBoxShape and btSphereShape (both trigger the bug).

Seeing that you can't reproduce it, i'm going to tinker on my side with bundled demos. Failing that, i'll have to endure eternal internet shame for undue bug report.
Still, i'm a bit intrigued a) that everything works fine but when there's some deletion/insertion while simulating b) using another broadphase implementation cures symptoms.

In any case, thanks for the clarification.
tbp
Posts: 4
Joined: Sat May 19, 2007 4:51 pm

Post by tbp »

Again on win32/msvc8sp1, with a release build of the original Bullet 2.50b0 and this patch

Code: Select all

--- CcdPhysicsDemo.cpp.orig     2007-03-21 16:16:14.000000000 +0100
+++ CcdPhysicsDemo.cpp  2007-05-20 02:37:04.343750000 +0200
@@ -99,9 +99,9 @@
        ///Please don't make the box sizes larger then 1000: the collision detection will be inaccurate.
        ///See http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=346

-//#define USE_GROUND_PLANE 1
+#define USE_GROUND_PLANE 1
 #ifdef USE_GROUND_PLANE
-       new btStaticPlaneShape(btVector3(0,1,0),10),
+       new btStaticPlaneShape(btVector3(0,1,0),0),
 #else
        new btBoxShape (btVector3(200,CUBE_HALF_EXTENTS,200)),
 #endif
... i can crash that demo if i hit 'end' while shooting boxes like my life depended on.

random backtrace

Code: Select all

>	ReleaseCcdPhysicsDemo.exe!gjkepa_impl::GJK::GJK(btStackAlloc * psa=0x3b396088, const btMatrix3x3 & wrot0={...}, const btVector3 & pos0={...}, const btConvexShape * shape0=0x012127e8, const btMatrix3x3 & wrot1={...}, const btVector3 & pos1={...}, const btConvexShape * shape1=0x012127e8, float pmargin=0.0010000000)  Line 142	C++
 	ReleaseCcdPhysicsDemo.exe!btGjkEpaSolver::Collide(btConvexShape * shape0=0x012127e8, const btTransform & wtrs0={...}, btConvexShape * shape1=0x012127e8, const btTransform & wtrs1={...}, float radialmargin=0.00000000, btStackAlloc * stackAlloc=0x3b396088, btGjkEpaSolver::sResults & results={...})  Line 604	C++
 	ReleaseCcdPhysicsDemo.exe!btGjkEpaPenetrationDepthSolver::calcPenDepth(btVoronoiSimplexSolver & simplexSolver={...}, btConvexShape * pConvexA=0x012127e8, btConvexShape * pConvexB=0x012127e8, const btTransform & transformA={...}, const btTransform & transformB={...}, btVector3 & v={...}, btVector3 & wWitnessOnA={...}, btVector3 & wWitnessOnB={...}, btIDebugDraw * debugDraw=0x01215348, btStackAlloc * stackAlloc=0x3b396088)  Line 38 + 0x2b bytes	C++
 	ReleaseCcdPhysicsDemo.exe!btGjkPairDetector::getClosestPoints(const btDiscreteCollisionDetectorInterface::ClosestPointInput & input={...}, btDiscreteCollisionDetectorInterface::Result & output={...}, btIDebugDraw * debugDraw=0x01215348)  Line 244	C++
 	ReleaseCcdPhysicsDemo.exe!btCollisionDispatcher::defaultNearCallback(btBroadphasePair & collisionPair={...}, btCollisionDispatcher & dispatcher={...}, btDispatcherInfo & dispatchInfo={...})  Line 353 + 0x14 bytes	C++
 	ReleaseCcdPhysicsDemo.exe!btCollisionPairCallback::processOverlap(btBroadphasePair & pair={...})  Line 310 + 0x15 bytes	C++
 	ReleaseCcdPhysicsDemo.exe!btAxisSweep3::processAllOverlappingPairs(btOverlapCallback * callback=0x0012febc)  Line 318	C++
 	ReleaseCcdPhysicsDemo.exe!btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache * pairCache=0x01215208, btDispatcherInfo & dispatchInfo={...})  Line 327	C++
 	ReleaseCcdPhysicsDemo.exe!btCollisionWorld::performDiscreteCollisionDetection()  Line 143 + 0xc bytes	C++
 	ReleaseCcdPhysicsDemo.exe!btDiscreteDynamicsWorld::internalSingleStepSimulation(float timeStep=0.016666668)  Line 266	C++
 	ReleaseCcdPhysicsDemo.exe!btDiscreteDynamicsWorld::stepSimulation(float timeStep=1.401e-045#DEN, int maxSubSteps=0x00000001, float fixedTimeStep=0.016666668)  Line 236	C++
 	ReleaseCcdPhysicsDemo.exe!CcdPhysicsDemo::clientMoveAndDisplay()  Line 298	C++
 	GLUT32.DLL!10004ac9() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for GLUT32.DLL]	
 	GLUT32.DLL!1000490f() 	
 	ReleaseCcdPhysicsDemo.exe!glutmain(int argc=0x00000001, char * * argv=0x01213570, int width=0x00000280, int height=0x000001e0, const char * title=0x00435524, DemoApplication * demoApp=0x012128e8)  Line 96	C++
 	ReleaseCcdPhysicsDemo.exe!main(int argc=0x00000001, char * * argv=0x01213570)  Line 218 + 0x1f bytes	C++
 	ReleaseCcdPhysicsDemo.exe!__tmainCRTStartup()  Line 327 + 0x12 bytes	C
 	kernel32.dll!7c816fd7() 	
  • I can't trigger that bug without the static plane.
  • As much as i'm sure there's no synchronization issue in my code, i'm not for that demo (because removal is triggered by input/glut).
  • But then, even if the crash point isn't exactly the same it looks suspiciously similar (note: there's much variation in crash point with that demo, it's more 'stable' in my app).
I'd need to see if i can get the same result with gcc and/or another platform.

edit: debug build reliably fails with "Assertion failed: proxy0 != proxy1, file btoverlappingpaircache.cpp, line 73" if you shoot, hit 'end', shoot.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

That was a useful reproducing case.

It has been fixed, please check and download Bullet 2.51.
Thanks for your help,
Erwin
tbp
Posts: 4
Joined: Sat May 19, 2007 4:51 pm

Post by tbp »

No, i'm the one who has to thank you for your timely fix.
DevO
Posts: 95
Joined: Fri Mar 31, 2006 7:13 pm

Post by DevO »

After updating to the new Bullet version btStaticPlaneShape do not work anymore if #define BP_USE_FIXEDPOINT_INT_32 1 is enabled.

For example in CCDPhysicDemo

Code: Select all

define USE_GROUND_PLANE 1
#ifdef USE_GROUND_PLANE
	new btStaticPlaneShape(btVector3(0,1,0),10),
#else
	new btBoxShape (btVector3(200,CUBE_HALF_EXTENTS,200)),
#endif
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

Are you sure?

Here both settings give the same results. However, the planeshape is at the wrong position by default, so most objects fall down. Can you try replace 10 by 0.5? For example:

Code: Select all

#define USE_GROUND_PLANE 1
#ifdef USE_GROUND_PLANE        
new btStaticPlaneShape(btVector3(0,1,0),0.5),
#else        
new btBoxShape (btVector3(200,CUBE_HALF_EXTENTS,200)),
#endif
Thanks,
Erwin
DevO
Posts: 95
Joined: Fri Mar 31, 2006 7:13 pm

Post by DevO »

Yes I am sure!

I have now download whole Bullet from SVN and changed this.

Code: Select all

#define BP_USE_FIXEDPOINT_INT_32 1

Code: Select all

#define USE_GROUND_PLANE 1
#ifdef USE_GROUND_PLANE
	new btStaticPlaneShape(btVector3(0,1,0),0),
#else
	new btBoxShape (btVector3(200,CUBE_HALF_EXTENTS,200)),
#endif
In ReleaseCcdPhysicsDemo.exe there is now no collision with plane.
Also in my application using Bullet from SVN there is no collision with btStaticPlaneShape at all.

Something seems to be wrong in btAxisSweep3 in the last release, unfortunately I can not find it until now.

Thanks,
Devid[/code][/quote]
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

Large floating point AABB values (plane shape has an 'infinite' bounding box), caused troubles in quantization (the sign-bit of the floating point values was carried over wrongly into the unsigned integer).

32bit integer broadphase in Subversion repository should be working now, and is available in the new Bullet 2.52 release

Thanks for reporting!
Erwin
DevO
Posts: 95
Joined: Fri Mar 31, 2006 7:13 pm

Post by DevO »

Thanks you for for solving this problem Erwin!