Skip to content

Instantly share code, notes, and snippets.

@qoh
Last active November 29, 2017 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qoh/a66f729d0e57b7e91201107adde864f0 to your computer and use it in GitHub Desktop.
Save qoh/a66f729d0e57b7e91201107adde864f0 to your computer and use it in GitHub Desktop.
local function checkjoint(world)
local joint = world:getJoints()[1]
print(string.format('type() = %s, getType() = %s', joint:type(), joint:getType()))
joint:setMotorEnabled(true)
end
function love.load()
local world = love.physics.newWorld()
local a = love.physics.newBody(world, 0, 0)
local b = love.physics.newBody(world, 0, 0)
love.physics.newRevoluteJoint(a, b, 0, 0) -- No reference kept
-- The object obtained from World:getJoints has the proper RevoluteJoint
-- metatable, and setMotorEnabled can be called
checkjoint(world)
-- Triggering manually for test, would happen eventually
collectgarbage()
-- Now that the joint has been garbage collected, it is recreated
-- incorrectly when retrieved again:
-- Its :type() is now 'Joint' (the base class, not the specific
-- RevoluteJoint), but its :getType() is still 'revolute', and
-- .setMotorEnabled no longer exists
checkjoint(world)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment