Page 1 of 1
Prevent joints from breaking.
Posted: Sun Sep 11, 2011 7:28 pm
by rnodal
Hello all,
I'm currently experiencing the situation where my joints break apart. I'm trying to simulate a chain using the RevoluteJoint.
I had it understood that once you join two bodies, in order for them to separate you have to do it manually. Has anyone experienced
the situation before?
Any suggestions as to what the problem may be would be great.
-r
Re: Prevent joints from breaking.
Posted: Sun Sep 11, 2011 7:42 pm
by Rad3k
rnodal wrote:Hello all,
I'm currently experiencing the situation where my joints break apart.
Oh, that's pretty bad. I'm afraid you have to go see a doctor.
sorry, I had to
Seriously though, what do you mean by breaking apart? Do the links break apart completely, and start behaving like there was no joint at all, or the joints just "stretch" under a load?
Re: Prevent joints from breaking.
Posted: Sun Sep 11, 2011 7:51 pm
by rnodal
The first case. The bodies start to behave as if they were not connected at all.
I think I may have fixed it but I'm not sure.
Here is the old code:
Code: Select all
local centerx, centery = link:getBody():getWorldCenter()
joint = love.physics.newRevoluteJoint(link:getBody(), lastLink:getBody(), centerx - (width * 0.5), centery)
joint:setCollideConnected(true)
and here is the new code:
Code: Select all
local centerx, centery = link:getBody():getWorldCenter()
joint = love.physics.newRevoluteJoint(link:getBody(), lastLink:getBody(), centerx - (width * 0.5), centery)
joint:setCollideConnected(true)
table.insert(chain.joints, joint)
It seems that lua was doing some garbage collection and maybe that was causing the joints to get destroyed?
I'm not 100% sure to be honest. Any more input would be great.
-r
Re: Prevent joints from breaking.
Posted: Sun Sep 11, 2011 8:09 pm
by bartbes
joint seems to be a global, so if you run this multiple times it gets overwritten. This, in turn, means that there is no longer a reference to the joint and it will, at some point, get garbage collected, meaning it will be removed from the simulation as well.
Re: Prevent joints from breaking.
Posted: Sun Sep 11, 2011 8:37 pm
by rnodal
Thank you for answering.
A little bit before the loop I have:
I'm sorry for omitting the piece of information.
Thank.
-r
Re: Prevent joints from breaking.
Posted: Sun Sep 11, 2011 9:00 pm
by Rad3k
rnodal wrote:It seems that lua was doing some garbage collection and maybe that was causing the joints to get destroyed?
You're probably correct. If you don't store the references to physics objects somewhere, they will get destroyed when Lua garbage-collects them - it's not enough to have them inside a world to prevent this. Your change should be enough to fix it if you don't discard the 'chain' table afterwards.
Re: Prevent joints from breaking.
Posted: Sun Sep 11, 2011 9:45 pm
by rnodal
So far so good with the change I made.
Thank you all for taking the time to help me.
-r