Page 1 of 1
can't get rid of warning on cpSpaceAddCollisionPairFunc
Posted: Sat Mar 21, 2009 12:27 pm
by nino
I'm on xCode 3.1.2 trying to build my project but I can't seem to get rid of a warning on arg 4 of cpSpaceAddCollisionPairFunc, where you pass the collision function. It works fine but I am fussy about clean builds so I want to make the warning go away.
I have tried it with and without the & and using int and cpCollFunc as the return type for my function. What am I doing wrong?
edit: the warning is incompatible pointer type.
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
Posted: Sun Mar 22, 2009 12:50 pm
by slembcke
That almost certainly means that the function you are trying to pass does not take the correct number/type of parameters. Check it against the type defined in the header.
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
Posted: Mon Mar 23, 2009 7:00 pm
by nino
the chipmunk type def is:
Code: Select all
typedef int (*cpCollFunc)(cpShape *a, cpShape *b, cpContact *contacts, int numContacts, cpFloat normal_coef, void *data);
my function prototype is:
Code: Select all
int VM_collision(cpShape *s1, cpShape *s2, cpContact* contacts, int numContacts, float normal_coef, void * data);
I pass it to cpSpace like:
Code: Select all
cpSpaceAddCollisionPairFunc(VM.sim, 0, 0, &VM_collision, NULL);
If I try cpCollFunc VM_collision then it complains about two things (something about a cast on the return).
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
Posted: Mon Mar 23, 2009 7:16 pm
by Buschmaster
What if you change:
Code: Select all
int VM_collision(cpShape *s1, cpShape *s2, cpContact* contacts, int numContacts, float normal_coef, void * data);
to:
Code: Select all
int VM_collision(cpShape *s1, cpShape *s2, cpContact* contacts, int numContacts, cpFloat normal_coef, void * data);]
or even:
Code: Select all
static int VM_collision(cpShape *s1, cpShape *s2, cpContact* contacts, int numContacts, cpFloat normal_coef, void * data);
Do you still see the warning then?
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
Posted: Mon Mar 23, 2009 7:21 pm
by nino
HA! I found it.
I had changed typedef double cpFloat; to typedef float cpFloat; in chipmunk.h and I forgot to change it back when i got your latest version.
I guess xCode is picky about function pointers. That was the only place it complained.
Thanks for the help on this. It was driving me nuts.
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
Posted: Tue Mar 24, 2009 11:38 am
by slembcke
Yeah. Looks like someone beat me to it about the cpFloat parameter.
You realize of course that it should be very picky about function pointers. If it wasn't it would allow you to call a function with the wrong types, sizes, or even number of parameters. This is very bad in general. The annoying part is that there are a lot of subtle mistakes that you can make that will work just fine (sometimes only for a specific platform/architecture) but the compiler will complain about.
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
Posted: Tue Mar 24, 2009 5:16 pm
by nino
I guess I would have found out the hard way if I had ever tried to use normal_coef.
Sadly I'm not even sure what that arg is for.
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
Posted: Wed Mar 25, 2009 11:18 am
by slembcke
You multiply it against the normals in the contact array in case Chipmunk had to swap the order of the shapes to satisfy the order defined in the collision pair definition. It will always be 1.0 or -1.0.