"Contact Removed" when body is destroyed

Hello,

first of all, this engine is a great achievement!

I am having a bit of an issue I dont know if I am handling well.... and I would like some suggestions or help.

When I destroy a body during a collision (that is, AFTER the physics Step(), because I buffer collisions and process them afterwards as suggested), Box2D creates a callback to "b2ContactListener::Remove()", which I buffer. BUT, I get corrupted data (0xfdfd) in USER data. This is because Box2D, in DEBUG mode, sets all deallocated memory to 0xfd to see errors.

Now my question: How should I process the "contact deleted" collision event, due to a body destruction? In the user data I store a pointer to my agent class of a game, which will handle the collision event properly. So, If I destroy the body with some user data, I will always receive events with 0xfdfd in user data... I dont know how I should manage it properly.

(note: I dont have this problem in Release modes, as Box2D doesnt write 0xfdfd , and bodies destroy correctly, I handle the collision callback properly without dangling pointers...)

Thank you for your help!
You must copy stuff when given it in an event. Not keep a pointer to it.
Aha,

when I read it, I went to the html manual, and Erin says cryptically this 😉

"Do not keep a reference to the contact points returned to b2ContactListener. Instead make a deep copy of the contact point data into your own buffer. The example below shows one way of doing this."

Which inclues as I see, my user data pointer!

Thanks a lot

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