Box2d assertion in love.physics.newPolygonShape

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.
TheWalruss
Prole
Posts: 5
Joined: Wed Sep 09, 2015 5:38 am

Box2d assertion in love.physics.newPolygonShape

Post 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?
Attachments
test.love
(2.54 KiB) Downloaded 60 times
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Box2d assertion in love.physics.newPolygonShape

Post 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.
User avatar
slime
Solid Snayke
Posts: 3133
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Box2d assertion in love.physics.newPolygonShape

Post by slime »

Box2D has a minimum distance between points in a polygon shape which you may be running into.
TheWalruss
Prole
Posts: 5
Joined: Wed Sep 09, 2015 5:38 am

Re: Box2d assertion in love.physics.newPolygonShape

Post 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?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Box2d assertion in love.physics.newPolygonShape

Post by Robin »

One goes through (1, 3) and (4, 2) and the other through (1, 2) and (4, 3), don't they?
Help us help you: attach a .love.
TheWalruss
Prole
Posts: 5
Joined: Wed Sep 09, 2015 5:38 am

Re: Box2d assertion in love.physics.newPolygonShape

Post 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?
User avatar
slime
Solid Snayke
Posts: 3133
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Box2d assertion in love.physics.newPolygonShape

Post 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.
TheWalruss
Prole
Posts: 5
Joined: Wed Sep 09, 2015 5:38 am

Re: Box2d assertion in love.physics.newPolygonShape

Post 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?
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Box2d assertion in love.physics.newPolygonShape

Post 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.
TheWalruss
Prole
Posts: 5
Joined: Wed Sep 09, 2015 5:38 am

Re: Box2d assertion in love.physics.newPolygonShape

Post by TheWalruss »

Scaling everything up works great! Thank you so much for the help!!!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 64 guests