windfield
windfield copied to clipboard
Attempt to use destroyed contact
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?
As a workaround, I modified windfield a bit to - instead of passing the contact
from Love2D directly - create a new table with the information I need:
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?
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.