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
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
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.
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).
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.
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.
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.
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
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.