Destroy body from within ContactListener::BeginContact. Lock

Hello.

I have a contact listener. From the BeginContact method I try to remove a body which I no longer need, but the problem is that that body is locked and an assertion is triggered.

How can I properly remove a body from within a BeginContact callback? What is the best approach?

I use world->DestroyBody(body) to destroy the body.

Thanks.

PS: If I comment out the line with "assert" and "if (islocked) return" it works exactly as I want it, but I prefere coding my games without modifying the framework. I'm sure the author had a very good reason for the "locked" thing.
Take a look at the 'collision processing' example in the test bed (you'll need to refer to the base class, Test, as well).

In the example, contacts are buffered during the callbacks, and then bodies are removed as a separate step. You don't have to do it exactly as shown in the test bed, but it does demonstrate the general idea, that is, to separate the 'callback' step from the 'remove' step so that you're not trying to remove bodies at the same time that contacts are being processed.

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