Is there a limit for coordinates?

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
CamillePaglia
Prole
Posts: 3
Joined: Wed May 03, 2023 8:51 pm

Is there a limit for coordinates?

Post by CamillePaglia »

Hi everyone,
I'm a uber newbie in gaming development, Lua and Love in general, so I may be missing something.

I'm developing a simple game where players must climb walls of a tower from within. On the walls I make some spears spawn randomly as obstacles.

What I have in mind it's an infinite scrolling type of game: I do a query search for colliders way up my position, and when I have a 0 hit I make walls and spears spawn vertically, so players will never run out of wall to climb.

Thing is, when I climbed at about -23458 on Y-axis, my game always crash, returning me this error:

Code: Select all

Error

libraries/windfield/windfield/init.lua:745: Box2D assertion failed: m_I > 0.0f

Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'newFixture'
libraries/windfield/windfield/init.lua:745: in function 'newPolygonCollider'
Scooping through windfield sourcecode and through love sourcecode itself, I managed to find that line at b2Body.cpp;334 (and at line 381 of the same file, for what it's worth).
I don't know C++ but I can see it's an assert fail, asserting that mass of a given Collider must be negative.

What I find baffling it's that it's always at the same spot.

So I'm wondering, and that's my question for you: did I hit some coordinate bound? So that it won't create anymore collider beyond some threshold?

Debugging last known spawn point for walls and spears I got

Code: Select all

WALL X L 50
WALL Y L -24420
WALL X R 550
WALL Y R -24420
SPEARS X R 550
SPEARS Y R -23527
SPEARS X L 200
SPEARS Y L -23733
I couldn't find any info about it, so thanks in advance!
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Is there a limit for coordinates?

Post by Bobble68 »

Oh hey I recently got a similar error!

If it's the same issue as what I got, the issue isn't with a number that is too large, rather one that is too small:

Code: Select all

Box2D assertion failed: m_I > 0.0f

Box2D (what Love uses for it's physics module) is written in C++, so you'll get C++ style programming when you get an error with it. Assertion being trying to state that something is true - if you fail an assertion, the statement isn't true. m_ usually indicates that I is a member of an object in C++, and the I refers to inertia - there's a similar issue here viewtopic.php?t=77266 that was caused by having 0 mass.

To get any more specific, we're going to have to see your code but hopefully this will be enough.
Dragon
CamillePaglia
Prole
Posts: 3
Joined: Wed May 03, 2023 8:51 pm

Re: Is there a limit for coordinates?

Post by CamillePaglia »

Bobble68 wrote: Wed May 03, 2023 9:29 pm Oh hey I recently got a similar error!

If it's the same issue as what I got, the issue isn't with a number that is too large, rather one that is too small:

Code: Select all

Box2D assertion failed: m_I > 0.0f

Box2D (what Love uses for it's physics module) is written in C++, so you'll get C++ style programming when you get an error with it. Assertion being trying to state that something is true - if you fail an assertion, the statement isn't true. m_ usually indicates that I is a member of an object in C++, and the I refers to inertia - there's a similar issue here viewtopic.php?t=77266 that was caused by having 0 mass.

To get any more specific, we're going to have to see your code but hopefully this will be enough.
First of all, thanks a lot for your detailed answer, so the inertia is the issue uh, thing is I'm creating objects the same way all the way up, until it crashes.

I'll delve in the thread you posted, btw if you want I'll leave the .love attached (don't judge the spaghetti code, it's a WIP :) )

once pressed enter, place yourself in the middle (so you won't hit spears) and press 'x' key to enter Creative mode, then hit 'up' key to fly up until it will crash at about 236m score, I'm posting the whole error

Code: Select all

Error

libraries/windfield/windfield/init.lua:745: Box2D assertion failed: m_I > 0.0f


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'newFixture'
libraries/windfield/windfield/init.lua:745: in function 'newPolygonCollider'
spears.lua:87: in function 'spawnLeftSpear'
spears.lua:58: in function 'spawn'
spears.lua:13: in function 'new'
walls.lua:56: in function 'spawnRandomSpear'
walls.lua:139: in function 'updateWalls'
main.lua:201: in function 'update'
[love "callbacks.lua"]:162: in function <[love "callbacks.lua"]:144>
[C]: in function 'xpcall'
as you can see in the traceback it comes from spawning a Spear, but as I said that method is called as always, only things different are number of objects and ofc Y...

I'll try to understand how inertia is involved, thanks a lot again!
Attachments
Game.love
(6.8 MiB) Downloaded 57 times
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Is there a limit for coordinates?

Post by Bobble68 »

CamillePaglia wrote: Wed May 03, 2023 9:52 pm
First of all, thanks a lot for your detailed answer, so the inertia is the issue uh, thing is I'm creating objects the same way all the way up, until it crashes.
Inertia isn't to do with angles, its to do with momentum. I'm not 100% confident on the subject, but it's about the object resisting changes to its movement, so it's effected by mass. I'll have a look at your code, I'll make an edit once I'm done.

EDIT:

The traceback shows that it seems to be an issue with spawning a new spear, its caused by something in the windfield library. Unsure exactly what is causing this though.

EDIT 2:

Still unsure what's causing it, but I am starting to wonder if you were right about it being a maxiumum number. Dividing the spear's y by 2 doubles the height at which it crashes.

If it is, I'm extremely surprised that Box2D can't handle that number. Floats (which is the number type that normally be used for this kind of thing) can be up to 340,282,300,000,000,000,000,000,000,000,000,000,000 so uh... idk what's causing that.


I know it's a bit late in development now, but you game is extremely simple - you really don't need or want to be using Box2D (Windfield) for this. Box2D is intended for more complex physics, not this more arcadey style you're going for. It's like using a Boeing 747 to go get milk - its bulky, over engineered and will probably cause more harm than good.

I know you're new to gaming development, but I'd seriously recommend making your own physics for this - the logic isn't too hard for what you're going for, and if you're stuck I'm sure people on this forum (including myself) wouldn't mind helping you with. Plus, you'll be a stronger developer for it.

EDIT 3:

You're The One, Neo
border.png
border.png (21.42 KiB) Viewed 1701 times
Dragon
User avatar
dusoft
Party member
Posts: 635
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Is there a limit for coordinates?

Post by dusoft »

Windfield is 6 years old and abandoned.
Consider using something up to date like https://github.com/HDictus/breezefield instead.
CamillePaglia
Prole
Posts: 3
Joined: Wed May 03, 2023 8:51 pm

Re: Is there a limit for coordinates?

Post by CamillePaglia »

Bobble68 wrote: Wed May 03, 2023 9:55 pm
CamillePaglia wrote: Wed May 03, 2023 9:52 pm
First of all, thanks a lot for your detailed answer, so the inertia is the issue uh, thing is I'm creating objects the same way all the way up, until it crashes.
Inertia isn't to do with angles, its to do with momentum. I'm not 100% confident on the subject, but it's about the object resisting changes to its movement, so it's effected by mass. I'll have a look at your code, I'll make an edit once I'm done.

EDIT:

The traceback shows that it seems to be an issue with spawning a new spear, its caused by something in the windfield library. Unsure exactly what is causing this though.

EDIT 2:

Still unsure what's causing it, but I am starting to wonder if you were right about it being a maxiumum number. Dividing the spear's y by 2 doubles the height at which it crashes.

If it is, I'm extremely surprised that Box2D can't handle that number. Floats (which is the number type that normally be used for this kind of thing) can be up to 340,282,300,000,000,000,000,000,000,000,000,000,000 so uh... idk what's causing that.


I know it's a bit late in development now, but you game is extremely simple - you really don't need or want to be using Box2D (Windfield) for this. Box2D is intended for more complex physics, not this more arcadey style you're going for. It's like using a Boeing 747 to go get milk - its bulky, over engineered and will probably cause more harm than good.

I know you're new to gaming development, but I'd seriously recommend making your own physics for this - the logic isn't too hard for what you're going for, and if you're stuck I'm sure people on this forum (including myself) wouldn't mind helping you with. Plus, you'll be a stronger developer for it.

EDIT 3:

You're The One, Neo
border.png
So I ran some tests and noticed that each new spears I spawned gained progressively more inertia, until it reached some arbitrary value resulting in that error.

I tried to set inertia to 0 but it didn't actually change it (I printed it to check it), I noticed in the thread you posted that inertia and mass are supposed to be modified by the same factor but that didn't work as well.

Long story short, I opted for a Rectangular Collider giving up on Polygonal one, since that's the one bugged :D and now it works like a charme (i.e. it doesn't die horribly).

I know windfield may be an overkill but it's convenient to work with high-level API already doing some work for me, especially since this is just some toy project I'm doing for fun, but looking under the hood showed me some stuff about Body, Fixture and Shape that I'll study further no doubt.

Thanks again for the kind help anyawy!
dusoft wrote: Thu May 04, 2023 8:49 am Windfield is 6 years old and abandoned.
Consider using something up to date like https://github.com/HDictus/breezefield instead.
thanks for the tip, I may look into it!
User avatar
pgimeno
Party member
Posts: 3657
Joined: Sun Oct 18, 2015 2:58 pm

Re: Is there a limit for coordinates?

Post by pgimeno »

Box2D uses single-precision floats. These can reach a very high number, but you lose precision quickly. I bet the root of the issue is a loss of precision. At 23458 (the sign doesn't matter), you get a precision of 2^-8 (i.e. 256 subdivisions per unit), and it's likely that that's too little for the physics engine and there's some internal calculation that overflows or underflows.

Using single-precision floats for coordinates is not recommended if your world is big. Maybe you can cheat - make a copy of the levels with higher numbers in a lower number, and teleport the player there, so as to keep the coordinates' absolute values low.
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Is there a limit for coordinates?

Post by Bobble68 »

pgimeno wrote: Thu May 04, 2023 9:32 pm Box2D uses single-precision floats. These can reach a very high number, but you lose precision quickly. I bet the root of the issue is a loss of precision. At 23458 (the sign doesn't matter), you get a precision of 2^-8 (i.e. 256 subdivisions per unit), and it's likely that that's too little for the physics engine and there's some internal calculation that overflows or underflows.

Using single-precision floats for coordinates is not recommended if your world is big. Maybe you can cheat - make a copy of the levels with higher numbers in a lower number, and teleport the player there, so as to keep the coordinates' absolute values low.
Sounds plausible, though I'm not sure why precision of world space would cause it to get inertia wrong. Honestly I'm kinda fascinated by this.
Dragon
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 7 guests