Page 1 of 1
Possible problem with cpSpaceEachBody deferencing NULL?
Posted: Thu Mar 10, 2011 4:07 am
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!
Re: Possible problem with cpSpaceEachBody deferencing NULL?
Posted: Thu Mar 10, 2011 9:46 am
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.
Re: Possible problem with cpSpaceEachBody deferencing NULL?
Posted: Fri Mar 11, 2011 5:12 am
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
Re: Possible problem with cpSpaceEachBody deferencing NULL?
Posted: Fri Mar 11, 2011 10:27 am
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.
Re: Possible problem with cpSpaceEachBody deferencing NULL?
Posted: Fri Mar 11, 2011 3:24 pm
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.
laser.

Re: Possible problem with cpSpaceEachBody deferencing NULL?
Posted: Fri Mar 11, 2011 7:25 pm
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.