Possible problem with cpSpaceEachBody deferencing NULL?

Discuss any Chipmunk bugs here.

Possible problem with cpSpaceEachBody deferencing NULL?

Postby yaddatrance » Thu Mar 10, 2011 4:07 am

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!
yaddatrance
 
Posts: 3
Joined: Thu Mar 10, 2011 3:55 am

Re: Possible problem with cpSpaceEachBody deferencing NULL?

Postby slembcke » Thu Mar 10, 2011 9:46 am

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/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Possible problem with cpSpaceEachBody deferencing NULL?

Postby yaddatrance » Fri Mar 11, 2011 5:12 am

You rock! Thanks for the insanely fast fix.

Heres the output of the test program :)

http://www.youtube.com/watch?v=suSLUs_0bo0
yaddatrance
 
Posts: 3
Joined: Thu Mar 10, 2011 3:55 am

Re: Possible problem with cpSpaceEachBody deferencing NULL?

Postby slembcke » Fri Mar 11, 2011 10:27 am

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/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Possible problem with cpSpaceEachBody deferencing NULL?

Postby yaddatrance » Fri Mar 11, 2011 3:24 pm

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
yaddatrance
 
Posts: 3
Joined: Thu Mar 10, 2011 3:55 am

Re: Possible problem with cpSpaceEachBody deferencing NULL?

Postby slembcke » Fri Mar 11, 2011 7:25 pm

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/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm


Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest

cron