Page 1 of 1

[Solved] physics: Assert fail when creating shapes.

Posted: Wed Dec 15, 2010 1:27 am
by An00biS
Hello.
I'm getting assert failures when creating love.physics shapes. I tried to figure out the reason, but I failed. The fact is, the failure appears when trying to create a very small or thin shapes.

My test script:

Code: Select all

function love.load()
	local world = love.physics.newWorld(0,0,100,100,0,0,true);
	local ground = love.physics.newBody(world, 0, 0, 0, 0);
	local top = love.physics.newRectangleShape(ground, 10, 10, 2, 2, 0);
end

function love.draw()
	love.graphics.printf("Loaded OK", 100, 100, 100);
end
This code ends up with message:

Code: Select all

love: modules/physics/box2d/Source/Collision/Shapes/b2PolygonShape.cpp:224: b2PolygonShape::b2PolygonShape(const b2ShapeDef*): Assertion `d.x >= 0.0f' failed.
Aborted (core dumped)
Different sizes produce different results. Here are some tests (values are attributes of newRectangleShape):
x2 = 3, y2 = 3 -> Passes
x2 = 10, y2 = 1 -> Assertion `d.y >= 0.0f' failed.
x2 = 1, y2 = 10 -> Assertion `d.x >= 0.0f' failed.
The newPolygonShape function showed me similar behaviour, though I didn't test it.

I suppose Box2D has no problem with tiny shapes, the documentation itself shows a 1 unit wide shapes.
Does anybody know what's going on here?

~An00biS

Edit: marked 'resolved'

Re: physics: Assert fail when creating shapes.

Posted: Wed Dec 15, 2010 4:20 am
by tentus
You're making a body that is right up in the corner of the world. Try making something that is further in, it might be going outside of the world.

Edit: Yep, looks like the smallest possible shape is 3 by 3. :huh: A couple of comments on your code: in Lua, you don't need ; though they don't hurt anything. You also have a bunch of extra parameters on newWorld that don't hurt anything but still shouldn't be there.

Code: Select all

function love.load()
	world = love.physics.newWorld(0,0,100,100)
	ground = love.physics.newBody(world, 0, 0, 0, 0)
	top = love.physics.newRectangleShape(ground, 0, 0, 3, 3, 0)
end

function love.draw()
	love.graphics.printf("Loaded OK", 100, 100, 100)
end

Re: physics: Assert fail when creating shapes.

Posted: Wed Dec 15, 2010 5:15 am
by Robin
Does it work if you call newWorld with (-100, -100, 100, 100) instead of (0, 0, 100, 100)?

Re: physics: Assert fail when creating shapes.

Posted: Wed Dec 15, 2010 5:44 am
by tentus
Robin wrote:Does it work if you call newWorld with (-100, -100, 100, 100) instead of (0, 0, 100, 100)?
That was my first thought too, but the result is the same. You just can't make a body less than 3,3.

Re: physics: Assert fail when creating shapes.

Posted: Wed Dec 15, 2010 6:00 am
by Robin
tentus wrote:That was my first thought too, but the result is the same. You just can't make a body less than 3,3.
Oh, right.

Box2D's units are meters. love.physics's are pixels (where the default is 30 px/m). So a body of 1x1 meter would be 30x30 pixels in LÖVE. You can change the scale with this function.

Re: physics: Assert fail when creating shapes.

Posted: Wed Dec 15, 2010 6:34 am
by tentus
Why 30px/m, out of curiosity? Why not, say, 32?

Re: physics: Assert fail when creating shapes.

Posted: Wed Dec 15, 2010 10:06 am
by An00biS
Robin wrote:Box2D's units are meters. love.physics's are pixels (where the default is 30 px/m).
You can change the scale with this function.
Ah, this explains everything - I thought the entered values went directly to Box2D.

Problem solved. Thanks.