Page 1 of 2

Box2d assertion in love.physics.newPolygonShape

Posted: Wed Sep 09, 2015 5:52 am
by TheWalruss
Hi!

I'm getting a very frustrating Box2D assertion when I use love.physics.newPolygonShape with a very simple rectangle. I've attached a simple test program that demonstrates the issue. I'm using Löve2d 9.2.

Code: Select all


--			4
--				3
--	1	
--		2

function love.load()
  	world = love.physics.newWorld(0,981,true)
	
	body = love.physics.newBody(world, 2, 3, "dynamic")
	shape = love.physics.newPolygonShape(1, 3, 2, 4, 4, 2, 3, 1)
	fixture = love.physics.newFixture(body,shape,1)
end
So you see, it's a nice, valid convex polygon. I illustrated the points in the comments above. What's going on here? Is this a known bug in Box2D? I've searched the Löve2d forums and the box2d forums and bug trackers, and can't find anything about the bug.

The following polygon does work:

Code: Select all

--local r = {295.01065732359, 500.32628156143, 304.98934267641, 499.67371843857, 301.47705992829, 449.79660575252, 291.9973088431, 450.41654071923 }
local r = {2, 4, 4, 3, 3, 1, 1, 2 }

--			3
--	4	
--				2
--		1
Also counter-clockwise... I don't see what Box2D thinks is different between the two.

Any help, please?

Re: Box2d assertion in love.physics.newPolygonShape

Posted: Wed Sep 09, 2015 3:52 pm
by ivan
In trig the y axis increases north and the x axis increases east. So you need to make sure your winding is ccw based on the trig projection.

Re: Box2d assertion in love.physics.newPolygonShape

Posted: Wed Sep 09, 2015 5:02 pm
by slime
Box2D has a minimum distance between points in a polygon shape which you may be running into.

Re: Box2d assertion in love.physics.newPolygonShape

Posted: Sat Sep 12, 2015 8:01 pm
by TheWalruss
In my post I show two polygons, both of which go counterclockwise, and with the same distance between points (which are all 1.41).

This one fails: (1, 3, 2, 4, 4, 2, 3, 1)

This one works: {2, 4, 4, 3, 3, 1, 1, 2 }

Plot it out on graph paper if you don't believe me about the point order and distances.

Can anybody try this and see if they get the same results, perhaps?

If so, I'll enter a bug report, I guess?

Re: Box2d assertion in love.physics.newPolygonShape

Posted: Sun Sep 13, 2015 10:10 am
by Robin
One goes through (1, 3) and (4, 2) and the other through (1, 2) and (4, 3), don't they?

Re: Box2d assertion in love.physics.newPolygonShape

Posted: Mon Sep 14, 2015 7:16 pm
by TheWalruss
The first goes through (1, 3), (2, 4), (4, 2), and (3, 1), and the other goes through (2, 4), (4, 3), (3, 1), and (1, 2), so yes. What's the significance, though?

Re: Box2d assertion in love.physics.newPolygonShape

Posted: Mon Sep 14, 2015 10:06 pm
by slime
The distance between (1,3) and (2,4) is 1.41, whereas the distance between every vertex in your second polygon (e.g. (2,4) and (4,3)) is 2.23.

You are running into the minimum distance between points in your first polygon. However, Box2d's calculated internal minimum is actually much larger than it should be due to a bug in its code.

Re: Box2d assertion in love.physics.newPolygonShape

Posted: Tue Sep 15, 2015 10:11 am
by TheWalruss
I'll blow up both polygons by a factor 100 and see if the bug goes away. If so, I'll see if I can do the physics sim in smaller units.

Do you know the value of b2_linearSlop, by the way?

The bug was reported in 2014 and there's been a patch available... I wonder how long until there's a fix in Löve2D. Any idea how long this type of thing takes for the devs to take care of?

Re: Box2d assertion in love.physics.newPolygonShape

Posted: Tue Sep 15, 2015 6:16 pm
by bobbyjones
It will take them 2 seconds if its a patch for box2d lol jk. But bug fixes are generally done in a timely matter IMO. New features are what take forever. If it were to be fixed though you would have to use the 0.10.0 version which isn't released yet.

Re: Box2d assertion in love.physics.newPolygonShape

Posted: Wed Sep 16, 2015 4:20 am
by TheWalruss
Scaling everything up works great! Thank you so much for the help!!!