windfield icon indicating copy to clipboard operation
windfield copied to clipboard

Attempt to use destroyed contact

Open codecat opened this issue 4 years ago • 3 comments

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?

codecat avatar Jul 21 '19 22:07 codecat

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

codecat avatar Jul 23 '19 17:07 codecat

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?

idbrii avatar Jun 18 '20 00:06 idbrii

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.

codecat avatar Jun 18 '20 09:06 codecat