Page 1 of 1
Crash when many boxes are added at the same position
Posted: Sun Mar 07, 2010 12:59 pm
by viblo
When I run this little code, which adds 16 boxes on the same position, take one simulation step and then adds 16 more boxes on the same position, and finally tries to step again, but this time it will crash.
Code: Select all
import pymunk as pm
from pymunk import Vec2d
pm.init_pymunk()
space = pm.Space()
for x in [1,2]:
for y in range(16):
size = 10
box_points = map(Vec2d, [(-size, -size), (-size, size), (size,size), (size, -size)])
body = pm.Body(10,20)
shape = pm.Poly(body, box_points, Vec2d(0,0))
space.add(body, shape)
space.step(1/50.0)
The code is in python using pymunk, but from the crash (inside the cpSpaceStep function of chipmunk) I think it's something in chipmunk and not python/pymunk related. It uses the latest trunk of chipmunk.
Re: Crash when many boxes are added at the same position
Posted: Tue Mar 16, 2010 2:26 pm
by slembcke
Nearly forgot to reply to this one, but luckily I had it bookmarked still.
I'm able to reproduce the issue, but I'm not sure what is causing it yet.
Re: Crash when many boxes are added at the same position
Posted: Tue Mar 16, 2010 3:07 pm
by slembcke
Ok, after looking into it a bit more this was a new bug that got added along with the contact batching. It had some pretty specific triggering requirements, so it shouldn't come up too much in practice.
It was an off by one error where I was allowing a shape pair to allocate CP_MAX_CONTACTS_PER_ARBITER + 1 contacts per arbiter. This is only an issue if you have exactly CP_MAX_CONTACTS_PER_ARBITER (default is 6) left in the contact buffer and it tries to allocate one too many.
I'll commit shortly.
Re: Crash when many boxes are added at the same position
Posted: Wed Mar 17, 2010 4:08 pm
by viblo
Nice you've found it, and good to know its not in the pymunk/python code
I have a little test/demo script that is included with pymunk which lets you add an array of 8x8 boxes. However, it has a little bug/feature so all the boxes are not created in a nice array but at the same position. When I just by chance pressed the add-box-array button quickly a couple of times I got the segfault and started to investigate it..
Re: Crash when many boxes are added at the same position
Posted: Sat Oct 30, 2010 3:27 pm
by viblo
Sorry to bring this up again, but did you fix this? Im in the process to update pymunk, and I get this crash even when I use the latest trunk of chipmunk?
Re: Crash when many boxes are added at the same position
Posted: Sun Oct 31, 2010 1:59 pm
by slembcke
From what I remember this was being caused because Chipmunk was overflowing the contact point buffer in some very specific circumstances. I did fix the issue that I found at the time, but somebody just found an even more specific bug a couple days ago. I'll try and remember to take a look at this tomorrow morning.
Re: Crash when many boxes are added at the same position
Posted: Mon Nov 01, 2010 11:32 am
by slembcke
I committed the fix for the bug to trunk. Does the crash still happen?
The bug should have been pretty rare, it would only happen when there were exactly six remaining contact points in the current contact buffer (which hold ~250 each) and you had a collision which generated 7 or more contact points. It should already be pretty rare to get 4 or more contact points, but adding boxes to the same spot might be generating a full 8 contact points.
Re: Crash when many boxes are added at the same position
Posted: Tue Nov 02, 2010 5:57 pm
by viblo
Yay, it seems to work without crashes now, good job
As I said, I have a bug/feature in one of the examples shipped with pymunk that places boxes on the same spot by mistake creating the bug all the time. Otherwise I think it would be a very very uncommon (and hard to find) crash..
Re: Crash when many boxes are added at the same position
Posted: Wed Nov 03, 2010 8:52 am
by slembcke
Yeah, I hadn't heard of it causing problems for anyone else in the wild fortunately. Hopefully no torch and pitchfork mobs at my door.