I have a Sphere (missile) that collides with a block(s).
In the collision handler thats called after the collision takes place I remove the sphere entity from the space and remove the event handler for the sphere.
Sometimes the sphere will collide with two blocks however so the handler is called a second time but at that point the handler has been removed (in the 1st call) so the Space.Update() throws an exception.
Is there a way to either flush out the message queue after the first collision?
or
How can I test for multiple contacts in the first collision?
Also am I correct in thinking that if I dont remove the handler when deleting the sphere it will never get cleaned up? Do I need to worry about this as not removing handler fixes the exception.
Thanks
Removing msg handler when deleting entities?
Re: Removing msg handler when deleting entities?
You could just explicitly keep track of the deletion, perhaps making use of the entity's Tag property, or clear all events on removal. Clearing an already empty set of Events shouldn't cause an exception. The event queue cannot be cleared, and testing for multiple contacts would be more work. However...
It shouldn't be be necessary. An event holds references; those references do not refer back to the event or the object that owns the event. Garbage collection can happen if no references exist to the object; so if the sphere is totally orphaned, it should eventually die off. If you're asking about the delegate itself, then it won't die unless nothing refers to it (the Sphere would have to be garbage collected or remove its event handler). Here's some related information: http://stackoverflow.com/questions/2982 ... m-occuringAlso am I correct in thinking that if I dont remove the handler when deleting the sphere it will never get cleaned up? Do I need to worry about this as not removing handler fixes the exception.