[box2d 2.02] Contact Listener Sound

Hello there.
I have encountered a problem while trying to add sound on my game through override the functions inside contactlistener class.
The problem is this.
At some point there are many objects around (bodies) and when the sounds are playing, the game sudently stops (i guess because theres at some points too many sounds playing at the same time).
And i Get the following errors:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at GameContactListener/Add()
at Box2D.Dynamics.Contacts::b2PolygonContact/Evaluate()
at Box2D.Dynamics.Contacts::b2Contact/Update()
at Box2D.Dynamics::b2ContactManager/Collide()
at Box2D.Dynamics::b2World/Step()
at Main/eFrame()


TypeError: Error #1009: Cannot access a property or method of a null object reference.
at GameContactListener/Persist()
at Box2D.Dynamics.Contacts::b2PolygonContact/Evaluate()
at Box2D.Dynamics.Contacts::b2Contact/Update()
at Box2D.Dynamics::b2ContactManager/Collide()
at Box2D.Dynamics::b2World/Step()
at Main/eFrame()

Any idea how can i get rid of these errors?
This is the code im using inside the Add function

Code: Select all


if(point.shape1.GetBody().GetUserData() is BallActor || point.shape2.GetBody().GetUserData() is BallActor)
{
   if(point.shape1.GetBody().GetLinearVelocity().x>20 || point.shape1.GetBody().GetLinearVelocity().x<-20 ||
     point.shape2.GetBody().GetLinearVelocity().x>20 || point.shape2.GetBody().GetLinearVelocity().x<-20 ||
      point.shape1.GetBody().GetLinearVelocity().y>20 || point.shape1.GetBody().GetLinearVelocity().y<-20 ||
      point.shape2.GetBody().GetLinearVelocity().y>20 || point.shape2.GetBody().GetLinearVelocity().y<-20)
   {
      if(point.shape1.GetBody().GetUserData() != null || point.shape2.GetBody().GetUserData() != null)
      {
         soundChannel=soundHit.play();
         soundChannel.soundTransform=Volume7;
      }
   }
}

I have solved the problem by raising a flag and handling the sound in my main class.

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