Hi,
How should I remove a collision handler in v7.0?
In v6.2 I was using `cpSpaceRemoveCollisionHandler` but I can't find any similar API in v7.0.
Thanks!
how to remove a collision handler in v7
- riq
- Posts: 37
- Joined: Mon Jun 23, 2008 1:16 pm
- Location: California, USA
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: how to remove a collision handler in v7
Allowing collision handlers to be removed in older versions was actually sort of a disaster. When a collision began, Chipmunk looked up the handler for it and stored it on the collision pair object. When you deleted the handler, it didn't check all active collisions and remove the handler from any that were using it. This is mostly what people wanted, since begin/events were expected to be matched. What about the user data parameter though? If you freed the memory associated with that when you deleted the handler, now you have a dangling pointer. There were other issues as well, and no obviously correct way to handle them. The only case where it wasn't "broken by design" is when you didn't use the user data pointer, and you wanted separate calls to happen even after you removed the handler.
The change in v7 was to expose the collision handler struct directly. When you call cpSpaceAddCollisionHandler(), it creates or returns the existing handler, and you can change the handler functions at any time. This gives you much more control than the previous behavior, but matching the old behavior exactly would be somewhat difficult.
The change in v7 was to expose the collision handler struct directly. When you call cpSpaceAddCollisionHandler(), it creates or returns the existing handler, and you can change the handler functions at any time. This gives you much more control than the previous behavior, but matching the old behavior exactly would be somewhat difficult.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
- riq
- Posts: 37
- Joined: Mon Jun 23, 2008 1:16 pm
- Location: California, USA
- Contact:
Re: how to remove a collision handler in v7
Ok. thanks. makes sense. I'll just replace the old handler with the "do nothing handler".
Who is online
Users browsing this forum: No registered users and 3 guests