Crash when many boxes are added at the same position

Discuss any Chipmunk bugs here.
Post Reply
viblo
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm
Contact:

Crash when many boxes are added at the same position

Post 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.
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Crash when many boxes are added at the same position

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Crash when many boxes are added at the same position

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
viblo
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm
Contact:

Re: Crash when many boxes are added at the same position

Post 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..
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
viblo
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm
Contact:

Re: Crash when many boxes are added at the same position

Post 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?
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Crash when many boxes are added at the same position

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Crash when many boxes are added at the same position

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
viblo
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm
Contact:

Re: Crash when many boxes are added at the same position

Post 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..
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Crash when many boxes are added at the same position

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests