b2Contact->IsTouching()=true, of a non colliding body

Hi. I post a link to my issue. Im not sure if it is a bug, but it seems to.

The fact is a body flying in the air (non touching anything), with a b2Contact class attached to it and returning true by the IsTouching() function.

http://box2d.org/forum/viewtopic.php?f=3&t=8245

Greetings!
Did you try using the latest version in SVN? If that doesn't help, please call b2World::Dump at the point where IsTouching is incorrect and attach the file here or on the issues page here: http://code.google.com/p/box2d/issues/list
Hi Erin.
Before anything thanks for box2d. It's great.

Im using 2.2.1 version (the latest on download page). [Box2D_v2.2.1.zip]

The issue: Body stood over the ground. I apply LinearImpulse to make him jump, then world->step. After this world->step I get a contact with IsTouching=true. Then render with DebugDraw and I see the body separated from the ground.

My code:

Code:
void Phy2DSystem::Update(float _ftime)
{
   for (int i = 0; i < num_scenes; i++)
   {
      Phy2DScene* _s = scene[i];

      // Update world
      _s->GetB2World()->Step(time_step, 10, 8);

      // Genera los contactos actuales
      for (int j = 0; j < _s->CheckCol_GetListSize(); j++)
      {
// Here I Get pointer to the box which I applied LinearImpulse to make it jump
         Phy2DBody* _phy2dbody = _s->CheckCol_GetBody(j);
         
         for (b2ContactEdge *ce = _phy2dbody->GetB2Body()->GetContactList(); ce; ce = ce->next)
         {
// Phy2DContact inherit from b2Contact
            Phy2DContact *_phy2dcontact = (Phy2DContact *)ce->contact;
         
            if (_phy2dcontact->IsTouching())
            {
               if (_s->debug)
               {
// I get inside this line after apply LinearImpulse and the world->step above. Then render and box is separated from ground. Using DebugDraw.
                  _s->GetB2World()->Dump();
               }
            }
         }
      }
   }
}


Dump info:
Quote:
b2Vec2 g(0.000000000000000e+000f, 1.100000000000000e+001f);
m_world->SetGravity(g);
b2Body** bodies = (b2Body**)b2Alloc(2 * sizeof(b2Body*));
b2Joint** joints = (b2Joint**)b2Alloc(0 * sizeof(b2Joint*));

{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(3.000000000000000e+001f, 6.909857940673828e+001f);
bd.angle = 0.000000000000000e+000f;
bd.linearVelocity.Set(0.000000000000000e+000f, -8.618643951416016e+001f);
bd.angularVelocity = 0.000000000000000e+000f;
bd.linearDamping = 0.000000000000000e+000f;
bd.angularDamping = 0.000000000000000e+000f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(16);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+000f;
bodies[0] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 6.000000238418579e-001f;
fd.restitution = 0.000000000000000e+000f;
fd.density = 5.000000000000000e-001f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(2);
fd.filter.groupIndex = int16(0);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(-1.950000047683716e+000f, -4.750000000000000e+000f);
vs[1].Set(1.950000047683716e+000f, -4.750000000000000e+000f);
vs[2].Set(1.950000047683716e+000f, 4.750000000000000e+000f);
vs[3].Set(-1.950000047683716e+000f, 4.750000000000000e+000f);
shape.Set(vs, 4);

fd.shape = &shape;

bodies[0]->CreateFixture(&fd);
}
}

{
b2BodyDef bd;
bd.type = b2BodyType(0);
bd.position.Set(5.120000457763672e+001f, 7.580000305175781e+001f);
bd.angle = 0.000000000000000e+000f;
bd.linearVelocity.Set(0.000000000000000e+000f, 0.000000000000000e+000f);
bd.angularVelocity = 0.000000000000000e+000f;
bd.linearDamping = 0.000000000000000e+000f;
bd.angularDamping = 0.000000000000000e+000f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+000f;
bodies[1] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 0.000000000000000e+000f;
fd.restitution = 0.000000000000000e+000f;
fd.density = 1.000000000000000e+000f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(2);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(0);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(-5.120000076293945e+001f, -5.000000000000000e-001f);
vs[1].Set(5.120000076293945e+001f, -5.000000000000000e-001f);
vs[2].Set(5.120000076293945e+001f, 5.000000000000000e-001f);
vs[3].Set(-5.120000076293945e+001f, 5.000000000000000e-001f);
shape.Set(vs, 4);

fd.shape = &shape;

bodies[1]->CreateFixture(&fd);
}
}

b2Free(joints);
b2Free(bodies);
joints = NULL;
bodies = NULL;


I hope it helps!!
Thanks!
Here the info of b2Contact class

Quote:
- _c 0x02396238 b2Contact *
+ [b2PolygonContact] {...} b2PolygonContact
+ __vfptr 0x00942aa0 const b2PolygonContact::`vftable' *
+ s_registers 0x00947de0 struct b2ContactRegister (* b2Contact::s_registers)[4] b2ContactRegister [4][4]
s_initialized true bool
m_flags 38 unsigned int
+ m_prev 0x00000000 {m_flags=??? m_prev=??? m_next=??? ...} b2Contact *
+ m_next 0x00000000 {m_flags=??? m_prev=??? m_next=??? ...} b2Contact *
+ m_nodeA {other=0x023960f8 contact=0x02396238 prev=0x00000000 ...} b2ContactEdge
+ m_nodeB {other=0x02395fb8 contact=0x02396238 prev=0x00000000 ...} b2ContactEdge
+ m_fixtureA 0x0239a0d0 {m_density=1.0000000 m_next=0x00000000 m_body=0x02395fb8 ...} b2Fixture *
+ m_fixtureB 0x0239a110 {m_density=0.50000000 m_next=0x00000000 m_body=0x023960f8 ...} b2Fixture *
m_indexA 0 int
m_indexB 0 int
+ m_manifold {points=0x02396278 localNormal={...} localPoint={...} ...} b2Manifold
m_toiCount 0 int
m_toi 1.0000000 float
m_friction 0.00000000 float
m_restitution 0.00000000 float
I'm seeing your code... the problem is that box2d solve collisions before move bodies. Box2d update touching flag in the collision step before move the body, so before to know that the contact won't be touching, box2d thinks it is touching. Then it moves the body and it is not touching. Box2D should update touching flag after move bodies, but it could have to test collisions again so I dont know what whould be a solution.
You can always freshen up contacts that you care about using b2Contact::Evaluate. That will not hinder overall performance.

Original thread: https://box2d.org/forum/viewtopic.php?t=8250