Problems with sleeping bodies

I'm remaking my own version of Breakout.

I have used Box2D a few times in my games and I'm not sure what is happening.

I have set my world object to allow sleeping of bodies

Code:
world = new b2World(worldAABB, gravity, true);


and made my own contact filter:

Code:
#include "Box2D.h"

class ContactFilter : public b2ContactFilter {

public:

   ContactFilter() {}

   bool ShouldCollide(b2Shape *shape1, b2Shape *shape2) {

      const b2FilterData filter1 = shape1->GetFilterData();
      const b2FilterData filter2 = shape2->GetFilterData();

      return true;

   }   //ShouldCollide() ends

};

#endif


and contactListener:

Code:
#include <iostream>

#include "ContactListener.h"
#include "Entity.h"
#include "Player.h"
#include "brick.h"
#include "ball.h"

// Called when a contact point is added. This includes the geometry and the forces.
void ContactListener::Add(const b2ContactPoint* point)
{

   Entity* entity1 = (Entity*)point->shape1->GetBody()->GetUserData();
   Entity* entity2 = (Entity*)point->shape2->GetBody()->GetUserData();

   //Check for bullet and building collisions. We need the bullet to get 'embedded' in the building.
   //That is, we just make it disappear.
   if (entity1->name == "Ball" && entity2->name == "Brick")
   {
      Ball* ball = (Ball*)entity1;

      Brick* brick = (Brick*)entity2;

      if (!brick->bodyDef.isSleeping)
      {
         b2Vec2 currentBallPosition = ball->body->GetPosition();

         b2Vec2 currentBrickPosition = brick->body->GetPosition();

         b2Vec2 collisionPosition;
      
         collisionPosition.x = currentBallPosition.x - currentBrickPosition.x;
         collisionPosition.y = currentBallPosition.y - currentBrickPosition.y;

         b2Vec2 currentBallVelocity = ball->body->GetLinearVelocity();

         if(collisionPosition.x < -0.75 && collisionPosition.y > -0.4 && collisionPosition.y < 0.4)
         {
            currentBallVelocity.x *= -1.0f;
         }
         else if(collisionPosition.x > 0.75 && collisionPosition.y > -0.4 && collisionPosition.y < 0.4)
         {
            currentBallVelocity.x *= -1.0f;
         }
         else
         {            
            if(collisionPosition.x < -0.75f && !level[brick->rowID][brick->columnID-1]->active)
            {
               ball->body->ApplyForce(b2Vec2(-10000.0, 10000.0), ball->body->GetPosition());   
            }
            else if(collisionPosition.x > 0.75f && !level[brick->rowID][brick->columnID-1]->active)
            {
               ball->body->ApplyForce(b2Vec2(10000.0, 10000.0), ball->body->GetPosition());   
            }
            else if(collisionPosition.y < 0)
            {
               ball->body->ApplyForce(b2Vec2(0.0, -10000.0), ball->body->GetPosition());   
            }
            else
            {
               ball->body->ApplyForce(b2Vec2(0.0, 10000.0), ball->body->GetPosition());   
            }
         }

         brick->deactivate();
      }

      ball = NULL;
      brick = NULL;
   }
   else if (entity2->name == "Ball" && entity1->name == "Brick")
   {
      Ball* ball = (Ball*)entity1;

      Brick* brick = (Brick*)entity2;

      if (!brick->bodyDef.isSleeping)
      {
         b2Vec2 currentBallPosition = ball->body->GetPosition();

         b2Vec2 currentBrickPosition = brick->body->GetPosition();

         b2Vec2 collisionPosition;
      
         collisionPosition.x = currentBallPosition.x - currentBrickPosition.x;
         collisionPosition.y = currentBallPosition.y - currentBrickPosition.y;

         b2Vec2 currentBallVelocity = ball->body->GetLinearVelocity();

         if(collisionPosition.x < -0.75 && collisionPosition.y > -0.4 && collisionPosition.y < 0.4)
         {
            currentBallVelocity.x *= -1.0f;
         }
         else if(collisionPosition.x > 0.75 && collisionPosition.y > -0.4 && collisionPosition.y < 0.4)
         {
            currentBallVelocity.x *= -1.0f;
         }
         else
         {            
            if(collisionPosition.x < -0.75f && !level[brick->rowID][brick->columnID-1]->active)
            {
               ball->body->ApplyForce(b2Vec2(-10000.0, 10000.0), ball->body->GetPosition());   
            }
            else if(collisionPosition.x > 0.75f && !level[brick->rowID][brick->columnID-1]->active)
            {
               ball->body->ApplyForce(b2Vec2(10000.0, 10000.0), ball->body->GetPosition());   
            }
            else if(collisionPosition.y < 0)
            {
               ball->body->ApplyForce(b2Vec2(0.0, -10000.0), ball->body->GetPosition());   
            }
            else
            {
               ball->body->ApplyForce(b2Vec2(0.0, 10000.0), ball->body->GetPosition());   
            }
         }

         brick->deactivate();
      }

      ball = NULL;
      brick = NULL;
   }   

   entity1 = NULL;
   entity2 = NULL;
}

// Called when a contact point persists. This includes the geometry and the forces.
void ContactListener::Persist(const b2ContactPoint* point)
{
   Entity* entity1 = (Entity*)point->shape1->GetBody()->GetUserData();
   Entity* entity2 = (Entity*)point->shape2->GetBody()->GetUserData();

   if (entity1->name == "Ball" && entity2->name == "Brick")
   {
      Ball* ball = (Ball*)entity1;

      Brick* brick = (Brick*)entity2;

      if (!brick->bodyDef.isSleeping)
      {
         b2Vec2 currentBallPosition = ball->body->GetPosition();

         b2Vec2 currentBrickPosition = brick->body->GetPosition();

         b2Vec2 collisionPosition;
      
         collisionPosition.x = currentBallPosition.x - currentBrickPosition.x;
         collisionPosition.y = currentBallPosition.y - currentBrickPosition.y;

         b2Vec2 currentBallVelocity = ball->body->GetLinearVelocity();

         if(collisionPosition.x < -0.75 && collisionPosition.y > -0.4 && collisionPosition.y < 0.4)
         {
            currentBallVelocity.x *= -1.0f;
         }
         else if(collisionPosition.x > 0.75 && collisionPosition.y > -0.4 && collisionPosition.y < 0.4)
         {
            currentBallVelocity.x *= -1.0f;
         }
         else
         {            
            if(collisionPosition.x < -0.75f && !level[brick->rowID][brick->columnID-1]->active)
            {
               ball->body->ApplyForce(b2Vec2(-10000.0, 10000.0), ball->body->GetPosition());   
            }
            else if(collisionPosition.x > 0.75f && !level[brick->rowID][brick->columnID-1]->active)
            {
               ball->body->ApplyForce(b2Vec2(10000.0, 10000.0), ball->body->GetPosition());   
            }
            else if(collisionPosition.y < 0)
            {
               ball->body->ApplyForce(b2Vec2(0.0, -10000.0), ball->body->GetPosition());   
            }
            else
            {
               ball->body->ApplyForce(b2Vec2(0.0, 10000.0), ball->body->GetPosition());   
            }
         }

         brick->deactivate();
      }

      ball = NULL;
      brick = NULL;
   }
   else if (entity2->name == "Ball" && entity1->name == "Brick")
   {
      Ball* ball = (Ball*)entity1;

      Brick* brick = (Brick*)entity2;

      if (!brick->bodyDef.isSleeping)
      {
         b2Vec2 currentBallPosition = ball->body->GetPosition();

         b2Vec2 currentBrickPosition = brick->body->GetPosition();

         b2Vec2 collisionPosition;
      
         collisionPosition.x = currentBallPosition.x - currentBrickPosition.x;
         collisionPosition.y = currentBallPosition.y - currentBrickPosition.y;

         b2Vec2 currentBallVelocity = ball->body->GetLinearVelocity();

         if(collisionPosition.x < -0.75 && collisionPosition.y > -0.4 && collisionPosition.y < 0.4)
         {
            currentBallVelocity.x *= -1.0f;
         }
         else if(collisionPosition.x > 0.75 && collisionPosition.y > -0.4 && collisionPosition.y < 0.4)
         {
            currentBallVelocity.x *= -1.0f;
         }
         else
         {            
            if(collisionPosition.x < -0.75f && !level[brick->rowID][brick->columnID-1]->active)
            {
               ball->body->ApplyForce(b2Vec2(-10000.0, 10000.0), ball->body->GetPosition());   
            }
            else if(collisionPosition.x > 0.75f && !level[brick->rowID][brick->columnID-1]->active)
            {
               ball->body->ApplyForce(b2Vec2(10000.0, 10000.0), ball->body->GetPosition());   
            }
            else if(collisionPosition.y < 0)
            {
               ball->body->ApplyForce(b2Vec2(0.0, -10000.0), ball->body->GetPosition());   
            }
            else
            {
               ball->body->ApplyForce(b2Vec2(0.0, 10000.0), ball->body->GetPosition());   
            }
         }

         brick->deactivate();
      }

      ball = NULL;
      brick = NULL;
   }   

   if (entity1->name == "Player" && entity2->name == "Ball")
   {
      Ball* ball = (Ball*)entity2;
      
      ball->body->ApplyForce(b2Vec2(0.0, -10000.0), ball->body->GetPosition());   

      ball = NULL;
   }
   else if (entity2->name == "Player" && entity1->name == "Ball")
   {
      Ball* ball = (Ball*)entity1;
      
      ball->body->ApplyForce(b2Vec2(0.0, -10000.0), ball->body->GetPosition());   

      ball = NULL;
   }

   entity1 = NULL;
   entity2 = NULL;
}

// Called when a contact point is removed. This includes the last computed geometry and forces.
void ContactListener::Remove(const b2ContactPoint* point)
{
}

// Called after a contact point is solved.
void ContactListener::Result(const b2ContactResult* point)
{
}


At the moment I'm trying to deactivate the brick that collides with the ball, this method sets the boolean value 'active' to false and sets bodyDef.isSleeping = true.

As you can see from my contact listener above, I'm checking if the brick's bodydef is sleeping and this seems to be working correctly.

As the ball starts off towards the bricks, it collides, comes back and bounces off the player. As it passes over the bricks that are sleeping it triggers the contact filter and the contact listener is called. As the bricks are sleeping nothing is called, but the ball still comes to a hault.

Why is this happening? It should cause a contact, but I don't see how the ball is being affected if the contact listener hasn't got anything defined for this case...

Any help would be much appreciated, thank you!
You cannot deactivate a body inside the callback because deactivation destroys all the contacts on the body, including the one you are currently accessing.

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