== Workaround for a Physics module issue ==

There is an [http://love2d.org/forum/tracker.php?p=1&t=191 unresolved issue] with the third callback of [[World:setCallbacks]], the remove callback. If there are active contacts when a shape is destroyed, the next physics update will cause a crash when LÖVE attempts to call the callback. This issue appears at least in LÖVE version 0.6.2.

To work around this problem, a shape must first leave from all the active contacts before it can be destroyed safely. This can be done by moving the shape into a special area, or more simply by setting the shape to not collide with anything.

<source lang="lua">
-- remove a shape from all contact categories
shape:setMask(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
-- add it into the pending destroy list
table.insert(removals, shape)
-- either remove the shape from the list of drawn objects, or mark
-- it with a flag so it won't be no longer drawn
</source>

After this is done, the shape will no longer have an affect on the world. After the next physics update is performed, it will also have lost all of its contacts, and can be safely destroyed.

<source lang="lua">
-- world update happens usually in love.update callback
world:update(dt)
-- you can follow it by destroying any shaped listed to be removed
for _, shape in ipairs(removals) do
	shape:destroy()
end
</source>

Remember that updating the world before removing the shape makes sure it will no longer be in contact with anything.

===See also===
* [[Shape:setMask]]
* [[Contact]]

[[Category:LÖVE]][[Category:Workarounds]]
== Other Languages ==
{{i18n|Remove Workaround}}