This repository has been archived by the owner on Mar 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Attempt to use destroyed contact #24
Comments
As a workaround, I modified windfield a bit to - instead of passing the local function copyContact(contact)
local ret = { normal = {} }
ret.normal.x, ret.normal.y = contact:getNormal()
return ret
end |
I had the same problem. I worked around it by building my own list of contacts in game code: if self.collider:enter(wall) then
local collision_data = self.collider:getEnterCollisionData(wall)
-- Using .contact causes 'Attempt to use destroyed contact.'
-- respondToCollision(collision_data, collision_data.contact:getPositions())
-- check our existing contacts instead.
local contact_list = collision_data.collider:getContacts()
for i,contact in ipairs(contact_list) do
local contact_points = {contact:getPositions()}
if #contact_points > 0 then
respondToCollision(collision_data, unpack(contact_points))
break
end
end
end I assume this is due to a change in love? Maybe windfield worked on an older version, but newer love is more aggressive with reclaiming allocated contacts? |
When I was looking into this previously I believe that is indeed the case. |
idbrii
added a commit
to idbrii/love-windfield
that referenced
this issue
Jul 3, 2021
Fix a327ex#24: error "Attempt to use destroyed contact." love doesn't guarantee Contacts survive beyond this callback (they may be destroyed in the same frame as creation). Make a copy so users can access later in the frame.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I keep getting "Attempt to use destroyed contact" sometimes whenever I use the contact in the
:exit
or:stay
event functions.Am I using them wrong? What's the correct way of using them? Or should I just switch to using actual event callbacks?
The text was updated successfully, but these errors were encountered: