tiny bodies breaking physics engine

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
jbm222
Prole
Posts: 4
Joined: Fri Apr 23, 2010 5:26 am

tiny bodies breaking physics engine

Post by jbm222 »

The attached lvledit.love is a wysiwyg level editor in its infant stages. Use the arrow keys to move the ball around. Left-click and drag to draw rectangles. Use the scroll wheel to switch between "fixed" (i.e. object that don't move) and "mobile" objects.

So here's the problem... when I draw really tiny objects, it crashes. The easiest way to reproduce the problem is to just click once. The attached error.jpg shows the error message that I get. This is for love 0.6.2, and I'm running on Windows Vista at the moment.

I know the code is kind of ugly at the moment as I'm still just getting the hang of lua. I'm not used working with a language that doesn't have OOP built into it. Anyway, any help figuring out why tiny objects break my "game" would be appreciated.
Attachments
lvledit.love
My level editor
(4.63 KiB) Downloaded 169 times
Error message
Error message
error.jpg (19.64 KiB) Viewed 4567 times
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: tiny bodies breaking physics engine

Post by bartbes »

Box2D loves to kill love, so yeah it's Box2D's fault. Anyway, what it means is that the distance between two points on the X-axis less than 0.0, which it can't handle.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: tiny bodies breaking physics engine

Post by kikito »

Making objects of 0 size doesn't make sense on the context of Box2D. The crashes make sense if you are trying to create not just tiny, but "cero-length" objects - it's its way of telling you that what you are asking it to do isn't possible.

I suggest you add a minimum dimension for your objects (1x1?), so if the height/width received is smaller, than it, it is reset to the minimum. The user clicking would generate very tiny objects - just no 0 length.

Alternatively, you can check the dimensions before creating and just cancel the creation if width or height are too small. The user clicking would not generate objects at all on that case.
When I write def I mean function.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: tiny bodies breaking physics engine

Post by bartbes »

Don't forget LÖVE scales.
User avatar
The Burrito
Party member
Posts: 153
Joined: Mon Sep 21, 2009 12:14 am
Contact:

Re: tiny bodies breaking physics engine

Post by The Burrito »

The smallest "safe" object is .1 X .1 units, and that should be your cutoff point, by default LÖVE scale is 30px/unit, thus 3X3 pixels is the default minimum.

I have a similar box drawing tool for my editor, and it simply cancels creation of the object if its less than 2X2 (I have a smaller physics scale).

Technically nothing is crashing, Box2D is simply informing us that it didn't create the shape. It would be nice if there was a way to suppress these messages, or even better if the functions to create shapes returned a success / fail .
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: tiny bodies breaking physics engine

Post by bartbes »

File a report.
jbm222
Prole
Posts: 4
Joined: Fri Apr 23, 2010 5:26 am

Re: tiny bodies breaking physics engine

Post by jbm222 »

The Burrito wrote:The smallest "safe" object is .1 X .1 units, and that should be your cutoff point, by default LÖVE scale is 30px/unit, thus 3X3 pixels is the default minimum.
My code was based on a tutorial which set the scale to 64px/unit. I added a check that would force the smallest objects to 4x4, but I guess it needed to be 6x6 to work with the scale. Thanks!

Should there be a bug/issue opened about this? I was surprised to see the assertion failure reported by the C++ runtime. If there's no return value from Box2D, then LÖVE could do the bounds checking before calling into the library.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: tiny bodies breaking physics engine

Post by Robin »

jbm222 wrote:Should there be a bug/issue opened about this? I was surprised to see the assertion failure reported by the C++ runtime. If there's no return value from Box2D, then LÖVE could do the bounds checking before calling into the library.
I agree: we simple lovers should not be exposed to the dark magic of Box2D (at least not that easily).
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest