Jump to content

Recommended Posts

Posted

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

Posted

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);

  • Upvote 1
trindieprod.png?dl=0spacer.png?dl=0steam-icon.png?dl=0twitter-icon.png?dl=0spacer.png?dl=0
  • 2 weeks later...
Posted
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.

Posted

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

  • 2 weeks later...
Posted

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.

  • 2 weeks later...
Posted

i tried this and it doesn't run on OS X. It compiles then crashes

bool Life()
{
 while(death=false)
 {
   if(death==true)
   return death;
 }
}

 

I have found the secret to infinite life

 

Did I help you out? Like my post!

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.

×
×
  • Create New...