Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Feb 22, 2012 4:14 pm 
Offline

Joined: Wed Feb 22, 2012 3:54 pm
Posts: 4
Hi there

I am having trouble getting the debug viewer to play nice. I have done the following :

Code:
class CBulletDebugDraw : public btIDebugDraw
{
   virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color);
   virtual void drawLine(const btVector3& from,const btVector3& to, const btVector3& fromColor, const btVector3& toColor);
   virtual void drawTriangle(const btVector3& v0,const btVector3& v1,const btVector3& v2,const btVector3& color, btScalar alpha ) { }

   virtual void   drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color) {};

   virtual void   reportErrorWarning(const char* warningString);

   virtual void   draw3dText(const btVector3& location,const char* textString) { };

   virtual void   setDebugMode(int debugMode) { };

   virtual int      getDebugMode() const ;
};

...

void CBulletDebugDraw::drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
   Vec3d vFrom(from.m_floats[0],from.m_floats[1],from.m_floats[2]);
   Vec3d vTo(to.m_floats[0],to.m_floats[1],to.m_floats[2]);
   g_Renderer.AddDebugLine(vFrom,vTo);
}

void CBulletDebugDraw::drawLine(const btVector3& from,const btVector3& to, const btVector3& fromColor, const btVector3& toColor)
{
   drawLine(from,to,fromColor);
}

int CBulletDebugDraw::getDebugMode() const
{
   return DBG_DrawWireframe;
}

void CBulletDebugDraw::reportErrorWarning( const char* warningString )
{
   ... logging code ...
}



I then create btDynamicsWorld, initialize all the necessary stuff, set an instance of the above class as my debug viewer and
add 3 rigid bodies with different kinds of shapes.
However, this causes an access violation in btCollisionWorld.cpp in the method debugDrawWorld(), line 1444 (not too sure how reliable that is).
I know this isn't too much to go on, but does anyone have an idea what could be causing this? Is there anything obvious I am missing, or something
I do not know regarding the debug viewer?
When I do not add the rigid bodies to the world the program runs fine. The physics also seems to be working fine when I do not use the debug viewer.

Any help would be much appreciated!
Thanks


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 7:26 am 
Offline
User avatar

Joined: Tue Jun 29, 2010 10:27 pm
Posts: 237
Everything looks ok to me. Can you check your Bullet source and see what line 1444 is (if there is one)?


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 7:40 am 
Offline

Joined: Wed Feb 22, 2012 3:54 pm
Posts: 4
Yea I marked the line here at the bottom

Code:
void   btCollisionWorld::debugDrawWorld()
{
   if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)
   {
      int numManifolds = getDispatcher()->getNumManifolds();
      btVector3 color(0,0,0);
      for (int i=0;i<numManifolds;i++)
      {
         btPersistentManifold* contactManifold = getDispatcher()->getManifoldByIndexInternal(i);
         //btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
         //btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());

         int numContacts = contactManifold->getNumContacts();
         for (int j=0;j<numContacts;j++)
         {
            btManifoldPoint& cp = contactManifold->getContactPoint(j);
            getDebugDrawer()->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),color);
         }
      }
   }

   if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb))
   {
      int i;

      for (  i=0;i<m_collisionObjects.size();i++)
      {
         btCollisionObject* colObj = m_collisionObjects[i];
         if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0)
         {
            if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe)
            {
               btVector3 color(btScalar(1.),btScalar(1.),btScalar(1.));
               switch(colObj->getActivationState())
               {
               case  ACTIVE_TAG:
                  color = btVector3(btScalar(1.),btScalar(1.),btScalar(1.)); break;
               case ISLAND_SLEEPING:
                  color =  btVector3(btScalar(0.),btScalar(1.),btScalar(0.));break;
               case WANTS_DEACTIVATION:
                  color = btVector3(btScalar(0.),btScalar(1.),btScalar(1.));break;
               case DISABLE_DEACTIVATION:
                  color = btVector3(btScalar(1.),btScalar(0.),btScalar(0.));break;
               case DISABLE_SIMULATION:
                  color = btVector3(btScalar(1.),btScalar(1.),btScalar(0.));break;
               default:
                  {
                     color = btVector3(btScalar(1),btScalar(0.),btScalar(0.));
                  }
               };

               debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);
            }
1444:            if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
            {
               btVector3 minAabb,maxAabb;
               btVector3 colorvec(1,0,0);
               colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
               btVector3 contactThreshold(gContactBreakingThreshold,gContactBreakingThreshold,gContactBreakingThreshold);
               minAabb -= contactThreshold;
               maxAabb += contactThreshold;

               btVector3 minAabb2,maxAabb2;

               if(colObj->getInternalType()==btCollisionObject::CO_RIGID_BODY)
               {
                  colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(),minAabb2,maxAabb2);
                  minAabb2 -= contactThreshold;
                  maxAabb2 += contactThreshold;
                  minAabb.setMin(minAabb2);
                  maxAabb.setMax(maxAabb2);
               }

               m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec);
            }
         }

      }
   }
}


Soo I'm guessing it breaks in the method debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);.
It does call my line drawing code before it breaks.

Thanks for the reply


Top
 Profile  
 
PostPosted: Thu Feb 23, 2012 2:12 pm 
Offline

Joined: Wed Jan 07, 2009 11:43 am
Posts: 98
Location: London
clutching at straws, but have you checked that m_debugDraw is a valid pointer at that point? It's interesting that the code above that line uses getDebugDraw() rather then m_debugDraw directly.


Top
 Profile  
 
PostPosted: Fri Feb 24, 2012 8:42 am 
Offline

Joined: Wed Feb 22, 2012 3:54 pm
Posts: 4
Ahhhh so I solved the issue. I was linking with a version of the bullet lib using double's, however
in my application #define BT_USE_DOUBLE_PRECISION was not defined. So on debugDrawObject's return
it was writing over the stack.

Thanks for the help though :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group