Physics object identity (possibly a bug in Löve)

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
Rad3k
Citizen
Posts: 69
Joined: Mon Aug 08, 2011 12:28 pm

Physics object identity (possibly a bug in Löve)

Post by Rad3k »

Consider the following piece of code:

Code: Select all

world = love.physics.newWorld(0, 0)
shape = love.physics.newCircleShape(1)
body = love.physics.newBody(world, 0, 0, 'dynamic')
fixture = love.physics.newFixture(body, shape)
same_fixture = body:getFixtureList()[1]

print(fixture == same_fixture)
print(rawequal(fixture, same_fixture))
In my case, it outputs

Code: Select all

true
false
Same applies to fixtures passed to collision callbacks, bodies from Fixture:getBody(), and probably every other objects that can be accessed in a similar way. I discovered this when I tried to make an object keep track of fixtures it's touching, by using a table with fixtures as keys and numbers of contacts (with the particular fixtures) as values. Current behavior complicates this quite a bit.

It seems like somewhere in the code, same box2d objects are being wrapped in different lua values. I wonder whether this is a bug, or is there a good reason for it to work like that. Any thoughts?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Physics object identity (possibly a bug in Löve)

Post by kikito »

What's rawequal? I haven't seen that one before.

EDIT: Ok, found it - rawequal . Hmm. The only option I can think about is using the Data of setData instead of trying to identify each body by its fixtures.
When I write def I mean function.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Physics object identity (possibly a bug in Löve)

Post by Boolsheet »

Yeah, I stumbled over that one too. This is a side effect of the chosen implementation because LÖVE has to juggle 3 things at the same time: The LÖVE object instance, the Box2D object pointer, and the Lua userdata proxy.

I believe the userdata proxy stuff would have to be rewritten to get the userdata equality back.
Shallow indentations.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Physics object identity (possibly a bug in Löve)

Post by bartbes »

It is a necessary evil, we can't duplicate full userdata without recreating the proxy, unless we'd know exactly where each userdata is.
Now, you might be thinking, this is possible, and it is (albeit crappy), but not with threads.
Rad3k
Citizen
Posts: 69
Joined: Mon Aug 08, 2011 12:28 pm

Re: Physics object identity (possibly a bug in Löve)

Post by Rad3k »

kikito wrote:What's rawequal? I haven't seen that one before.

EDIT: Ok, found it - rawequal . Hmm. The only option I can think about is using the Data of setData instead of trying to identify each body by its fixtures.
This is probably the way I'll go, though it requires that I assign unique data to all fixtures that I want to keep track of.
The other way would be to iterate over a table checking each element if it's the one I'm looking for, but it's a rather ugly hack.
bartbes wrote:It is a necessary evil, we can't duplicate full userdata without recreating the proxy, unless we'd know exactly where each userdata is.
Now, you might be thinking, this is possible, and it is (albeit crappy), but not with threads.
I guess I'll take your word for it ;)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 86 guests