Sensor contact listener question

Sooo..... I've got a shape i use as a sensor.

i listen for ADD and REMOVE contact events. i'd like a certain effect to happen to bodies whose shapes are intersecting with the sensor.

the idea is that when an ADD event occurs involving the sensor, i add the body of the intersecting shape to an Array, "BODIES", if it's not already in there. on a REMOVE event of a shape, i remove the associated body from BODIES.

the problem is that REMOVE events are called even though the shapes are completely within this sensor. i figured once a shape enters, a REMOVE event wouldn't be called again until it is no longer intersecting.

i plan on working around it by just comparing AABBs, but I'd like to understand why REMOVE is being called here.... and also if i'm doing something wrong.
eh.... that alternative won't work so well when i rotate the sensor. neither will using QueryAABB
There can be multiple add's and removes, but they come in pairs. Use reference counting to determine when there are 0. There are better solutions in the works, but not yet, sorry.
hey no problem...

yeah i have no trouble adding and removing bodies when add and remove are called. i just don't understand what is causing the remove to be called. a shape will enter the large sensor area, and an add is called. it'll hang out in there for a second or so, then the remove is called. seems bizarre.
Adds and removes are per contact point, and a pair of shapes can have multiple (2) contact points. This doesn't make much sense for sensors in deep collision, but they are treated the rest.
hey thanks boris i wasn't thinking about what you were trying to tell me initially. bodies were being removed when REMOVE was called because i was acting as though there was only one contact point possible per shape. PERSIST seems like a much better idea... for some reason i didn't think it was called for sensors
Sorry,

I have a question about to remove bodies from the world when it is/are contact to the Ground.
I used the "ContactListener"
when there is ADD event occur, i will use "DestroyBody" to remove the bodies.
Sometime, there have an error.....

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Box2D.Collision::b2BroadPhase/Query()
at Box2D.Collision::b2BroadPhase/DestroyProxy()
at Box2D.Collision.Shapes::b2Shape/http://www.box2d.org/ns/b2internal::DestroyProxy()
at Box2D.Dynamics::b2World/DestroyBody()


What's the problem??
How can i correct this error??
BorisTheBrave wrote:
There can be multiple add's and removes, but they come in pairs. Use reference counting to determine when there are 0. There are better solutions in the works, but not yet, sorry.


Hi BorisTheBrave!

Can you explain it better? Same example for "reference counting to determine when there are 0"? Maybe using std::map and id->key?
BTW, which other solutions do you mean?

Thanks a lot for your time.
Quote:
which other solutions do you mean


i think he is referring this Erin Catto's recent work on changing how contacts work.
http://www.box2d.org/forum/viewtopic.php?f=3&t=1784&start=70

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