Jump to content

[LE3]UpdatePhysicsHook


AggrorJorn
 Share

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 *"

Link to comment
Share on other sites

  • 2 weeks later...
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

"If our brains were simple enough for us to understand them, we'd be so simple that we couldn't." - Ian Stewart 1995.

Link to comment
Share on other sites

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. ):

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...