Problem with info property of physics.body [FIXED]

I’ve been having problems using the info property of physics bodies.

I use it to hold a references to my game objects and call a method on them in the collision callback to react to the collision. However, I’ve found that the method is sometimes called on the wrong object. It’s as if the info fields are getting switched around between the body objects.

Anyone else seen this? Is it a known bug? I couldn’t find it in the issue tracker.

Sorry about this, it’s a known bug. I think it was reported earlier on the forums. It should be fixed in 1.3.1, I’ll ask @John to clarify. I think he needed the same feature and ended up finding a workaround until he fixed it.

@Nat this is a known bug. For now the work around is to have a table that maps from your body to the object you want associated with it. i.e.

body = physics.rigidbody(...)
gameObject = GameObject(body)
bodyToGameObjectMap[body] = gameObject

-- meanwhile in collide

function collide(contact)
    local gameObjectA = bodyToGameObjectMap[contact.bodyA]
    local gameObjectB = bodyToGameObjectMap[contact.bodyB]

Don’t forget to nil references in the table when you delete a body / gameObject pair.

I’ll have a fix with 1.3.1 as Simeon mentioned. Hope this helps.

This is fixed in 1.3.1