destroying joints

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
kaishaku
Prole
Posts: 14
Joined: Sun Aug 31, 2008 10:42 pm

destroying joints

Post by kaishaku »

A nil joint remains active in box2d until the garbage collector runs.

Is there a way to destroy joints explicitly without calling collectgarbage?
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: destroying joints

Post by rude »

Not currently, no.

I think my original reasoning was:

Code: Select all

joint = love.physics.newJoint( etc )

-- Do stuff

-- Removes instantly. (Pointer to Box2D object is destroyed here).
joint:destroy() 

-- Methods can still be called, but will fail in all
-- kinds of horrible ways. 
x1, y1, x2, y2 = joint:getPoints() -- doom
That goes for the other objects too. I have no problem with the methods failing after destroy has been called, but they need to fail with the usual error message.

I just got this (obvious) idea:

Code: Select all

function Joint:destroy()
  self:remove()
  self.__index = function() return error("Object has been destroyed.") end
end
... but I'm not sure if that works. I'll check it out. (Other suggestions are welcome).
kaishaku
Prole
Posts: 14
Joined: Sun Aug 31, 2008 10:42 pm

Re: destroying joints

Post by kaishaku »

It might be ok to fail in horrible ways after an explicit destroy().

Can you simply assign the symbol a nil value after the explicit destroy()?

Something like that, or possibly your example (not sure), would be ok too.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 9 guests