Page 1 of 1

Physics cause love crash randomly

Posted: Fri Jun 03, 2011 12:36 am
by Alex22
Hey guys, I have this problem now since quite a long time and I finally chose to hunt this sucker down.

http://dl.dropbox.com/u/1519805/steroid.love
Try the .love out and youll notice that after some shooting around(hold right mouse button) it crashes. I really have no idea how that happens.
The weird thing, it happens without any pattern, sometimes it crashes right on the second or third shot and sometimes it doesn't crash at all(very unlikely).

So I hope this could maybe be a known problem|bug and some wonderboy comes and tells me what im doing wrong :D

Greetings, Alex22.

Re: Physics cause love crash randomly

Posted: Fri Jun 03, 2011 1:06 am
by Taehl
"for i,v in pairs(shells) do if love.timer.getTime() - v.crttime > v.lifetime then" What are crttime and lifetime, and why aren't they mentioned anywhere else in game.lua?

Re: Physics cause love crash randomly

Posted: Fri Jun 03, 2011 1:13 am
by slime
The error that box2d gives when it crashes is

Code: Select all

Assertion failed: (m_pairCount < b2_maxPairs && m_freePair != b2_nullPair), function AddPair, file src/modules/physics/box2d/Source/Collision/b2PairManager.cpp, line 134.
Not sure what that means exactly though.

Re: Physics cause love crash randomly

Posted: Fri Jun 03, 2011 1:18 am
by Alex22
:3 Sorry for my messy code, im working on this for quite a while now and im not the type of person who comments its code properly...

crttime is the time the shell was created and lifetime is the limit in seconds how long it does live until its going to be removed.
The function it is in is doing the mentioned above. (the crttime is set in the Shell:init in classes.lua)

Re: Physics cause love crash randomly

Posted: Fri Jun 03, 2011 3:20 am
by ivan
slime wrote:The error that box2d gives when it crashes is

Code: Select all

Assertion failed: (m_pairCount < b2_maxPairs && m_freePair != b2_nullPair), function AddPair, file src/modules/physics/box2d/Source/Collision/b2PairManager.cpp, line 134.
Not sure what that means exactly though.
Box2D has several constants. This script seems to have violated the maximum collisions pair count.
Not 100% sure, but most likely this is caused by trying to create a very large number of shapes.

Re: Physics cause love crash randomly

Posted: Fri Jun 03, 2011 3:25 am
by BlackBulletIV
slime wrote:The error that box2d gives when it crashes is

Code: Select all

Assertion failed: (m_pairCount < b2_maxPairs && m_freePair != b2_nullPair), function AddPair, file src/modules/physics/box2d/Source/Collision/b2PairManager.cpp, line 134.
Not sure what that means exactly though.
Pretty sure I hit this when creating too many shapes, over 4000 is the mark I think.

Re: Physics cause love crash randomly

Posted: Sat Jun 04, 2011 4:22 pm
by Alex22
I'm not sure but I really don't think that the problem is, that too many shapes have been created (does destroying the body, also remove the shapes?)
I placed some variables in my code, which increased everytime a shape was created. The results were, again, completly random and without any pattern.

Btw. @Slime: Where did you get the Error message from? When crashing I only recieve this shitty, unhelpful Windows report thing.

Re: Physics cause love crash randomly

Posted: Sat Jun 04, 2011 4:33 pm
by ivan
Alex22 wrote:I'm not sure but I really don't think that the problem is, that too many shapes have been created
Box2D uses constant-sized arrays so don't be surprised.
After all, Box2D is a C++ library so it's hard to safely export it to Lua without re-writing half the code and making everything 'dynamic'.
Alex22 wrote:(does destroying the body, also remove the shapes?)
Yes.
Alex22 wrote:I placed some variables in my code, which increased everytime a shape was created. The results were, again, completly random and without any pattern.
Because of Lua's garbage collector crashes can often appear random.
Generally, if you are able to produce a C/C++ crash from a Lua script than there's something seriously wrong in your code.
Alex22 wrote:Btw. @Slime: Where did you get the Error message from? When crashing I only recieve this shitty, unhelpful Windows report thing.
He is probably running Love2D in debug mode.
You'll need a C/C++ compiler and all the Love2D source code to do that.

Re: Physics cause love crash randomly

Posted: Sat Jun 04, 2011 5:10 pm
by slime
Alex22 wrote:Btw. @Slime: Where did you get the Error message from? When crashing I only recieve this shitty, unhelpful Windows report thing.
I ran the game through my console in OS X, and it showed up there.

Re: Physics cause love crash randomly

Posted: Sat Jun 11, 2011 6:19 pm
by Alex22
Oh, if anyone cares or has the same problem:

I had a bug in my shape creation code which caused each shape to be created ~5-25 times. Fixing this has stopped the chrasing.
But I find it curious, that box2d already crashes at approximately 1.5k shapes.

Thanks for your help :D