how to remove a collision handler in v7

Official forum for the Chipmunk2D Physics Library.

how to remove a collision handler in v7

Postby riq » Wed Feb 17, 2016 8:28 pm

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
riq
 
Posts: 37
Joined: Mon Jun 23, 2008 1:16 pm
Location: California, USA

Re: how to remove a collision handler in v7

Postby slembcke » Thu Feb 18, 2016 10:15 am

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
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: how to remove a collision handler in v7

Postby riq » Sat Feb 20, 2016 1:05 am

Ok. thanks. makes sense. I'll just replace the old handler with the "do nothing handler".
User avatar
riq
 
Posts: 37
Joined: Mon Jun 23, 2008 1:16 pm
Location: California, USA


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest

cron