Crash when ~900 rigidbodies collide

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
azert24
Prole
Posts: 4
Joined: Wed Apr 27, 2022 7:16 am

Crash when ~900 rigidbodies collide

Post by azert24 »

Hey guys,

I'm looking to maximize the number of rigid bodies in a small simulation I'm making. However, I'm encountering trouble when too many physics objects collide : Love2D just crashes :(

Is there any way to do anything about this without doing object pooling ? (I really want to be able to simulate all of these objects.)
Maybe there is something terribly wrong with my code, I'm still new to Love after all.

Steps to reproduce my issue:
  • Download my .love and run it
  • Spawn around 900 balls with the down arrow key or by pressing q. There is a counter in the top right of the window.
  • Press g to activate gravity. Sometimes you need to nudge some of the balls by spawning new balls as they tend to go to sleep.
  • Watch the game crash as all the balls fall down :death:

I've included a minimal .love file. I hope you can check the code out.

Specs : Intel integrated graphics + i5-7200U CPU @ 2.50GHz
OS : Tested on windows and linux (debian), same results --> crash
Love version : tested on 11.3
Attachments
april-debug.love
(3.8 KiB) Downloaded 92 times
User avatar
BrotSagtMist
Party member
Posts: 615
Joined: Fri Aug 06, 2021 10:30 pm

Re: Crash when ~900 rigidbodies collide

Post by BrotSagtMist »

No crash here, just ultra slow fps.
You are simply hitting a bordercase at the bottom where there are more balls than avaiable space.
This would would freak out any simulation.
obey
azert24
Prole
Posts: 4
Joined: Wed Apr 27, 2022 7:16 am

Re: Crash when ~900 rigidbodies collide

Post by azert24 »

BrotSagtMist wrote: Thu Apr 28, 2022 3:37 am No crash here, just ultra slow fps.
You are simply hitting a bordercase at the bottom where there are more balls than avaiable space.
This would would freak out any simulation.
Ok I understand, but is there anything I can do to prevent this ?

Maybe there is a way to detect this is going to happen and delete some physic objects.
Or is there a way to increase box2D's timestep so that it's more performant (but less accurate).
User avatar
Gunroar:Cannon()
Party member
Posts: 1088
Joined: Thu Dec 10, 2020 1:57 am

Re: Crash when ~900 rigidbodies collide

Post by Gunroar:Cannon() »

Don't make .... 900 rigid bodies?
Maybe if it's past a certain number like 500 or 700 you can delete the older ones (that is if you store them in a table, if not then.... store them in a table).
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
knorke
Party member
Posts: 240
Joined: Wed Jul 14, 2010 7:06 pm
Contact:

Re: Crash when ~900 rigidbodies collide

Post by knorke »

For me it runs at 60 fps as long most of the balls are bouncing around. (even with 1000 balls)
But when the balls stop bouncing and settle on the the ground, fps goes down to 30.
Then suddendly all the balls jump up and a few frames later it freezes.
I think it is like BrotSagtMist wrote, the simulation freaks out. Too many contacts at the same time or something.
Maybe if an object has come to rest, set it to "sleeping" or "inactive"? https://love2d.org/wiki/Body:setSleepingAllowed I never used those functions.
azert24
Prole
Posts: 4
Joined: Wed Apr 27, 2022 7:16 am

Re: Crash when ~900 rigidbodies collide

Post by azert24 »

Gunroar:Cannon() wrote: Thu Apr 28, 2022 9:42 am Don't make .... 900 rigid bodies?
Maybe if it's past a certain number like 500 or 700 you can delete the older ones (that is if you store them in a table, if not then.... store them in a table).
I know what you mean, but it seems like the engine can handle that large amount of physics objects and performs really well as long as they don't collide all at once.

There are a lot of things you can do with this large amount of physics objects.

I'm trying to find a failsafe in case they do collide all at once, which doesn't happen frequently.
azert24
Prole
Posts: 4
Joined: Wed Apr 27, 2022 7:16 am

Re: Crash when ~900 rigidbodies collide

Post by azert24 »

knorke wrote: Thu Apr 28, 2022 10:22 am For me it runs at 60 fps as long most of the balls are bouncing around. (even with 1000 balls)
But when the balls stop bouncing and settle on the the ground, fps goes down to 30.
Then suddendly all the balls jump up and a few frames later it freezes.
I think it is like BrotSagtMist wrote, the simulation freaks out. Too many contacts at the same time or something.
Maybe if an object has come to rest, set it to "sleeping" or "inactive"? https://love2d.org/wiki/Body:setSleepingAllowed I never used those functions.
I will try this tonight, maybe it'll work.

I was wondering what your computer specs were, it could be that your PC is just a lot more powerful than mine ^^
User avatar
BrotSagtMist
Party member
Posts: 615
Joined: Fri Aug 06, 2021 10:30 pm

Re: Crash when ~900 rigidbodies collide

Post by BrotSagtMist »

At the bottom you have more balls than space for balls leading to an exponential pushing around of objects.
Computer specs are worth a crap for exponential problems.
What you could actually do is to place the walls in an angle so that the pressure can get released up instead bouncing between the walls.
obey
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 60 guests