Syntax Error for Bullet Callback Function (C++)

Started by
3 comments, last by karwosts 13 years, 6 months ago
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!
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Advertisement
I'm not particularly familiar with Bullet, but have you tried taking the address of the function?
world->setInternalTickCallback(&BulletTickCallback, static_cast<void*>(this));

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

The parameters of the function BulletTickCallback and the function pointer type do not match. Param1 is const on one and not the other.
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


[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
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 :)
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

This topic is closed to new replies.

Advertisement