I submitted a bug report here: https://bitbucket.org/rude/love/issues/ ... et-me-weld and the basics is that I didn't know BOX2D locks the world during the collision callback functions. I wanted to help the project by adding the following code to various parts of the Wiki:
{{notice|Making changes to a [[World]] is not allowed inside of the [[beginContact]], [[endContact]], [[preSolve]], and [[postSolve]] callback functions, as BOX2D locks the world during these callbacks.}}
in various pages within love.physics and wanted to ask the community if you could copy and paste that notice where it is most relevant, and accurate, and make sure that I'm not spreading false information. It would suck if I was the cause of false information to someone else.
Thanks!
Documentation on BOX2D Locks
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- slime
- Solid Snayke
- Posts: 3132
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Documentation on BOX2D Locks
I think only the World:setCallbacks page should have it, since almost every love.physics object method that modifies the object can't be used (that's a lot of things to document), whereas World:setCallbacks is what affects those functions, so people who don't use that method won't care about those notices.
Re: Documentation on BOX2D Locks
There are 2 ways to make changes based on collisions.Not sure if this is considered off-topic, but what are the work-arounds for making welds after a collision?
First, you can use external flags:
Code: Select all
local marked = {}
function beginContact(fixture1, fixture2)
local body1 = fixture1:getBody()
local body2 = fixture2:getBody()
if body1 == trigger then
marked[body2] = true
elseif body2 == trigger then
marked[body1] = true
end
end
function love.update(dt)
for body in pairs(marked) do
-- make changes here
marked[body] = nil
end
end
Code: Select all
function love.update(dt)
local bodies = world:getBodies()
for _, body in ipairs(bodies) do
if body:isTouching(trigger) do
-- make changes here
end
end
end
Who is online
Users browsing this forum: No registered users and 92 guests