I'm trying to react to collisions, but it seems like if I have too many contacts they are destroyed in the same frame they're created. Are they only valid in setCallbacks's `beginContact` function? The docs don't mention any limitations and sometimes they survive several frames.
I've boiled it down to a .love that draws normals for all contacts. It clears the list of contacts after every update, but it still gets "Attempt to use destroyed contact" when you try to stuff all the balls into a corner (which I assume is generating a lot more contacts).
The problem is essentially in this code:
Code: Select all
local physics = {
normals = {},
on_enter = {},
}
function physics.collisionOnEnter(fixture_a, fixture_b, contact)
table.insert(physics.on_enter, {
contact = contact,
})
end
function love.update(dt)
world:update(dt)
for _,event in ipairs(physics.on_enter) do
local dx,dy = event.contact:getNormal() -- error here
local point = {event.contact:getPositions()}
for i=1,#point,2 do
local x,y = point[i], point[i+1]
table.insert(physics.normals, {x,y, x+dx, y+dy})
end
end
table_clear(physics.on_enter)
...
(Using love 11.3.)