title: Cocos2d collision works but cannot be detected by b2contactListener
body: <p>i've got a problem about b2contactListener.</p>
  
  <p>i have these two classes:</p>
  
  <pre><code>class Terrain
  class Hero
  </code></pre>
  
  <p>Each class got a method called:
  <code>getHeroBody</code> -> returns the <code>b2body</code> of the hero.
  <code>getTerrainBody</code> -> returns the <code>b2body</code> of the Terrain.</p>
  
  <p>Each class got a method called <code>(id)initWithWorld:(b2World *)world;</code> that takes a <code>b2World</code> </p>
  
  <p>When i create 2 objects on these classes i use the same <code>b2World</code>.</p>
  
  <p>Now the problem is:
  Collisions work but all the method to detect these collisions return always a null array, 0, in other words no collisions.</p>
  
  <p>here is the declaration</p>
  
  <pre><code>MyContactListener *_contactListener;
  
  _contactListener = new MyContactListener();
  _world-&gt;SetContactListener(_contactListener);
  </code></pre>
  
  <p>here is 2 cycles the game never enters:</p>
  
  <p>//FIRST WAY NOT WORKING</p>
  
  <pre><code>std::vector&lt;MyContact&gt;::iterator pos;
  for(pos = _contactListener-&gt;_contacts.begin();pos != _contactListener-&gt;_contacts.end(); ++pos) { //never enters
      MyContact contact = *pos;
      for(b2Fixture *terrain_fixture = [_terrain getTerrainBody]-&gt;GetFixtureList(); terrain_fixture; terrain_fixture = terrain_fixture-&gt;GetNext()){
          for (b2Fixture *char_fixture = [_hero getHeroBody]-&gt;GetFixtureList(); char_fixture; char_fixture = char_fixture-&gt;GetNext()){
              if ((contact.fixtureA == terrain_fixture &amp;&amp; contact.fixtureB == char_fixture) ||
                  (contact.fixtureA == char_fixture &amp;&amp; contact.fixtureB == terrain_fixture)) {
                  isontheground = YES;
              }
          }
      }
  }
  </code></pre>
  
  <p>//SECOND WAY NOT WORKING</p>
  
  <pre><code>for (b2Contact* contact = _world-&gt;GetContactList(); contact; contact = contact-&gt;GetNext()){ //never enters
      isontheground = YES;
  }
  </code></pre>
  
  <p>FIRST WAY USE THIS CLASS</p>
  
  <pre><code>MyContactListener::MyContactListener() : _contacts() {
  </code></pre>
  
  <p>}</p>
  
  <p>MyContactListener::~MyContactListener() {
  }</p>
  
  <pre><code>void MyContactListener::BeginContact(b2Contact* contact) {
      // We need to copy out the data because the b2Contact passed in
      // is reused.
      MyContact myContact = { contact-&gt;GetFixtureA(), contact-&gt;GetFixtureB() };
      _contacts.push_back(myContact);
  }
  
  void MyContactListener::EndContact(b2Contact* contact) {
      MyContact myContact = { contact-&gt;GetFixtureA(), contact-&gt;GetFixtureB() };
      std::vector&lt;MyContact&gt;::iterator pos;
      pos = std::find(_contacts.begin(), _contacts.end(), myContact);
      if (pos != _contacts.end()) {
          _contacts.erase(pos);
      }
  }
  
  void MyContactListener::PreSolve(b2Contact* contact,
                                   const b2Manifold* oldManifold) {
  }
  
  void MyContactListener::PostSolve(b2Contact* contact,
                                    const b2ContactImpulse* impulse) {
  }
  </code></pre>