[Solved] physics: Assert fail when creating shapes.

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
An00biS
Prole
Posts: 21
Joined: Thu Nov 13, 2008 9:55 am
Location: mapy.cz/?query=rajhrad

[Solved] physics: Assert fail when creating shapes.

Post 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'
Last edited by An00biS on Wed Dec 15, 2010 10:07 am, edited 1 time in total.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: physics: Assert fail when creating shapes.

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

Re: physics: Assert fail when creating shapes.

Post by Robin »

Does it work if you call newWorld with (-100, -100, 100, 100) instead of (0, 0, 100, 100)?
Help us help you: attach a .love.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: physics: Assert fail when creating shapes.

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

Re: physics: Assert fail when creating shapes.

Post 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.
Help us help you: attach a .love.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: physics: Assert fail when creating shapes.

Post by tentus »

Why 30px/m, out of curiosity? Why not, say, 32?
Kurosuke needs beta testers
An00biS
Prole
Posts: 21
Joined: Thu Nov 13, 2008 9:55 am
Location: mapy.cz/?query=rajhrad

Re: physics: Assert fail when creating shapes.

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot] and 10 guests