how to remove a collision handler in v7

Official forum for the Chipmunk2D Physics Library.
Post Reply
User avatar
riq
Posts: 37
Joined: Mon Jun 23, 2008 1:16 pm
Location: California, USA
Contact:

how to remove a collision handler in v7

Post by riq »

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!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: how to remove a collision handler in v7

Post by slembcke »

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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
riq
Posts: 37
Joined: Mon Jun 23, 2008 1:16 pm
Location: California, USA
Contact:

Re: how to remove a collision handler in v7

Post by riq »

Ok. thanks. makes sense. I'll just replace the old handler with the "do nothing handler".
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests