Sign in to follow this  
karwosts

Syntax Error for Bullet Callback Function (C++)

Recommended Posts

Hi. I'm trying to implement the bullet tick callback (calls the function on every physics tick, and I've followed the direction best I can tell, but I can't make sense of the error I'm seeing in MSVC++.

Header:

class PhysicsEngine {
...
public:
PhysicsEngine();
...
};

static void BulletTickCallback(const btDynamicsWorld *world, btScalar timeStep);




Cpp:

#include "PhysicsEngine.h"
#include <BulletDynamics\Dynamics\btDynamicsWorld.h>

void BulletTickCallback(const btDynamicsWorld *world, btScalar timeStep) {
printf("The world just ticked by %f seconds\n", (float)timeStep);
}

PhysicsEngine::PhysicsEngine(){

world = new btDiscreteDynamicsWorld(...);
world->setInternalTickCallback(BulletTickCallback, static_cast<void*>(this));
}




The compiler is flagging my argument BulletTickCallback to setInternalTickCallback saying:


error C2664: 'btDynamicsWorld::setInternalTickCallback' : cannot convert parameter 1
from 'void (__cdecl *)(const btDynamicsWorld *,btScalar)' to 'btInternalTickCallback'
1> None of the functions with this name in scope match the target type


This is the prototype function for btInternalTickCallback:

typedef void (*btInternalTickCallback)(btDynamicsWorld *world, btScalar timeStep);




Which looks the same as my function, but I'm not sure why it won't take it.

The simple example given on bullet site doesn't show much more than this, which I believe I've done:


void myTickCallback(const btDynamicsWorld *world, btScalar timeStep) {
printf("The world just ticked by %f seconds\n", (float)timeStep);
}

// And then somewhere after you construct the world:

mWorld->setInternalTickCallback(myTickCallback);




If I paste in that exact code it complains about the exact same thing for myTickCallback.

Am I missing something fundamental? I'm not experienced with function pointers.

Thanks!

Share this post


Link to post
Share on other sites
That didn't work either.


world_->setInternalTickCallback(&BulletTickCallback, static_cast<void*>(this));




error C2664: 'btDynamicsWorld::setInternalTickCallback' : cannot convert parameter 1
from 'void (__cdecl *)(const btDynamicsWorld *,btScalar)' to 'btInternalTickCallback'
1> None of the functions with this name in scope match the target type



Share this post


Link to post
Share on other sites
Quote:
Original post by empirical2
The parameters of the function BulletTickCallback and the function pointer type do not match. Param1 is const on one and not the other.


Hey you're right, didn't notice that. They must have changed the function since the wiki was written.

Thanks for the extra pair of eyes, works now :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this