can't get rid of warning on cpSpaceAddCollisionPairFunc

Official forum for the Chipmunk2D Physics Library.
Post Reply
nino
Posts: 9
Joined: Thu Nov 22, 2007 8:21 am
Contact:

can't get rid of warning on cpSpaceAddCollisionPairFunc

Post 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.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: can't get rid of warning on cpSpaceAddCollisionPairFunc

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
nino
Posts: 9
Joined: Thu Nov 22, 2007 8:21 am
Contact:

Re: can't get rid of warning on cpSpaceAddCollisionPairFunc

Post 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).
Buschmaster
Posts: 71
Joined: Sat Dec 20, 2008 12:16 pm
Location: Minnesota
Contact:

Re: can't get rid of warning on cpSpaceAddCollisionPairFunc

Post 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?
nino
Posts: 9
Joined: Thu Nov 22, 2007 8:21 am
Contact:

Re: can't get rid of warning on cpSpaceAddCollisionPairFunc

Post 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.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: can't get rid of warning on cpSpaceAddCollisionPairFunc

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
nino
Posts: 9
Joined: Thu Nov 22, 2007 8:21 am
Contact:

Re: can't get rid of warning on cpSpaceAddCollisionPairFunc

Post 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.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: can't get rid of warning on cpSpaceAddCollisionPairFunc

Post 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.
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 24 guests