Possible problem with cpSpaceEachBody deferencing NULL?

Discuss any Chipmunk bugs here.
Post Reply
yaddatrance
Posts: 3
Joined: Thu Mar 10, 2011 3:55 am
Contact:

Possible problem with cpSpaceEachBody deferencing NULL?

Post by yaddatrance »

I just started playing with 5.3.4 and my test app keeps getting seg faults after a minute or two (seemingly randomly, but a noticably short period after a collision). After beating my head I put little breakpoints in my code and the library and narrowed it down to cpSpaceEachBody() following the next=body->node.next to NULL.

It is still possible that I am improperly tickling the space->sleepingComponents somehow because in the eachBody() iterator I have it performing
a if cpBodyIsSleeping then apply cpBodySetVel... (thats all the function does at the moment FYI)

Any tips on how to work around this (or a "You're doing it wrong!") would be helpful.

Thanks!
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Possible problem with cpSpaceEachBody deferencing NULL?

Post by slembcke »

Ah, yep that's a bug. The problem is that cpSpaceEachBody() doesn't lock the space but it should. When iterating it's data structures (during cpSpaceStep() and queries), a cpSpace is locked so that it knows to throw an error when you try to add/remove something. It also builds a list of bodies to be awoken when the the lock is released as waking a body requires moving thing around between data structures. It never occurred to me that cpSpaceEachBody() would have the same problem.

I fixed it in trunk.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
yaddatrance
Posts: 3
Joined: Thu Mar 10, 2011 3:55 am
Contact:

Re: Possible problem with cpSpaceEachBody deferencing NULL?

Post by yaddatrance »

You rock! Thanks for the insanely fast fix.

Heres the output of the test program :)

http://www.youtube.com/watch?v=suSLUs_0bo0
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Possible problem with cpSpaceEachBody deferencing NULL?

Post by slembcke »

Wow. That is very cool. Care to share a little more info? I'd like to make a blog post about that if you wouldn't mind.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
yaddatrance
Posts: 3
Joined: Thu Mar 10, 2011 3:55 am
Contact:

Re: Possible problem with cpSpaceEachBody deferencing NULL?

Post by yaddatrance »

No problem... I'll have more interesting stuff coded up tonight!

You might recognize the physics engine, but the display hardware is using a 2 watt whitelight laser with 30kpps galvos. We built our own laser control hardware and software. The system is focused on real-time laser effects for laser shows. You can see the interactive nature in this video. http://www.youtube.com/watch?v=JKAqTKxyI8g (This video wasn't taken by us, we handed the ipad out at SOCALEM)

laser controller, features true 16 bit X & Y axis positioning and 64-bit color control.
Image

laser.
Image
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Possible problem with cpSpaceEachBody deferencing NULL?

Post by slembcke »

Very cool. I shared the link around with some friends and basically everybody's reaction was "I want one!". Heh.

I wish I had the time to do more with electronics stuff. I used to be really interested in it when I was a kid, but programming takes up most of my time now. It's still pretty cool that people are using my code to do stuff like that.
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 3 guests