Page 1 of 1

Add safeness

Posted: Fri Aug 28, 2009 8:50 am
by zaerl
Hi there

I'm using your (fabulous) library in a small project on the iPhone (no cocos-2d powered). The code is very well written and I really enjoy the results you can achieve. So thanks for the good job.

I suggest to add some degree of safeness on the next releases. A good start, in my opinion, is to add some protection against SEGFAULT. For example in function cpBodySetMass:

Code: Select all

void
cpBodySetMass(cpBody *body, cpFloat mass)
{
	// a simple check
	if(!body) return;

	body->m = mass;
	body->m_inv = 1.0f/mass;
}
in order to avoid the simplest errors.

Anyway keep up the good job.

P.S. I can help if you want. I am an experienced C programmer.

Re: Add safeness

Posted: Fri Aug 28, 2009 9:25 am
by slembcke
Makes sense. Though I would probably use an assertion as it's more helpful to get an immediate error than trying to figure out why something isn't working even when it's getting called. (shakes fist at Obj-C and it's behaviour of ignoring messages to nil)

Re: Add safeness

Posted: Sat Aug 29, 2009 1:47 am
by Tam Toucan
I'd rather see asserts used for this. Like you say I want to know if I've got a null and I don't want redundant checks in the library. Ok the above isn't going to be called much, but you never know.

Just being pedantic, but you would have to check for mass equals zero as well....for me stuff like this is low priority

Re: Add safeness

Posted: Sat Aug 29, 2009 7:54 am
by zaerl
Well yes it's low priority but it will be a good add. SEGFAULTs are quite annoying.

Have a nice day (I'm shaking my fist against ObjC policies.)