Jump to content
AggrorJorn

[LE3]UpdatePhysicsHook

Recommended Posts

Having some issues with adding a physics hook to an entity.

 

//.h
void PlayerUpdate(Entity* entity);

// .cpp
void PlayerUpdate(Entity* entity)
{
//update player
}
bool App::Start()
{
//Somewhere in start function
System::AddHook(Entity::UpdatePhysicsHook,PlayerUpdate);


ERROR:

IntelliSense: argument of type "void (App::*)(Leadwerks::Entity *entity)" is incompatible with parameter of type "void *"

Share this post


Link to post

Hi Aggror,

 

I have this working if the hook is added to the entity itself... I had no need to define it in .h

 

void UpdateMyPhysicsHook(Entity* entity)
{
blah blah
}


entity->AddHook(Entity::UpdatePhysicsHook, UpdateMyPhysicsHook);

Share this post


Link to post
ERROR:

IntelliSense: argument of type "void (App::*)(Leadwerks::Entity *entity)" is incompatible with parameter of type "void *"

Your compiler is rightfully complaining that your function pointer isn't of the correct type ie "void *".

 

The error lies within the declaration of System::AddHook() which has "void *" as the second parameter. AddHook should expect a function pointer of type void NOT a void pointer as they are in fact two completely different things and this should be classified as a typo bug.

 

The correct declaration for System::AddHook() should have been this....

typdef void (*vFunc)(Leadwerks::Entity *);

AddHook(int hookid, vFunc hook) {
...
}

As a temporary measure you call cast all your function pointers to void pointers but generally speaking this is considered dangerous in the C++ world and some compilers may not allow you even to do that. In a case were compilation has been successful you will often run into instability issues, memory address violations or other runtime errors... Avoid!

 

See this discussion on the subject...

 

http://stackoverflow...er-as-parameter

Share this post


Link to post

Good explanation, didnt know/realized that AddHook is the real problem.

 

Of course using void* is a bad thing, because void* can be anything. But there are exceptions for example if you know what void* represents, then it shouldnt be a problem to cast it ( beginthread etc. ):

Share this post


Link to post

Will this bug be fixed? or has anyone found a stable solution? I thought maybe it would be fixed in the next build, but im still unable to compile on OSX using AddHook with a void pointer.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...