xtreampb Posted March 25, 2013 Share Posted March 25, 2013 hey all i'm trying to add a collisions hook. Can someone help me with what i'm doing wrong //.h file void Break(Entity* entity0, Entity* entity1, float* position, float* normal, float speed); //CPP file this->Full->AddHook(Entity::CollisionHook, *Break)//my entity and adding the hook to my entity void Stone::Break(Entity* entity0, Entity* entity1, float* position, float* normal, float speed) { this->Full->Hide(); //blah blah blah } thank you for your help, ~Xtreampb~ Quote 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! Link to comment Share on other sites More sharing options...
Rick Posted March 25, 2013 Share Posted March 25, 2013 The hooks are generally all normal C functions. Looks like your Break() is part of the Stone class? Quote Link to comment Share on other sites More sharing options...
xtreampb Posted March 25, 2013 Author Share Posted March 25, 2013 yes that is correct as well as Full. Quote 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! Link to comment Share on other sites More sharing options...
xtreampb Posted March 25, 2013 Author Share Posted March 25, 2013 what am i doing wrong? Quote 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! Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 25, 2013 Share Posted March 25, 2013 I had the same issue. All I needed to do was remove the declaration in the header. http://www.leadwerks.com/werkspace/topic/6321-le3updatephysicshook/ Quote Link to comment Share on other sites More sharing options...
xtreampb Posted March 25, 2013 Author Share Posted March 25, 2013 ok so i removed the prototype from my header and added it to the top of my CPP file. Still getting an error. I'm using OSX if that makes a difference. Quote 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! Link to comment Share on other sites More sharing options...
tjheldna Posted March 31, 2013 Share Posted March 31, 2013 Makes a big difference, It's broken. Same function I created works in Windows, but not in OSX. I forgot to do a bug report for this. Quote Link to comment Share on other sites More sharing options...
MCP Posted April 1, 2013 Share Posted April 1, 2013 @xstreampb: Have to tried removing the prototype altogether? The problem maybe that your prototypes have not been declared with the correct namespace hence the error that you are getting (Re thread aggror supplied). Also you don't need a '*' before your Break function parameter in the AddHook function call. Quote "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 More sharing options...
tjheldna Posted April 1, 2013 Share Posted April 1, 2013 Yep, I did mine without the prototype and still did not work I'm 90% sure it's an OSX bug. Quote Link to comment Share on other sites More sharing options...
xtreampb Posted April 1, 2013 Author Share Posted April 1, 2013 yes i have removed the prototype completely Quote 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! Link to comment Share on other sites More sharing options...
Admin Posted April 1, 2013 Share Posted April 1, 2013 You don't need that asterisk in front of the function argument. Quote Link to comment Share on other sites More sharing options...
MCP Posted April 1, 2013 Share Posted April 1, 2013 Refer this thread for solution... http://www.leadwerks.com/werkspace/topic/6321-le3updatephysicshook/ Quote "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 More sharing options...
xtreampb Posted April 1, 2013 Author Share Posted April 1, 2013 this is what i got in my CPP file void Coll(Entity* entity0)//, Entity* entity1, float* position, float* normal, float speed) { } this->Full->AddHook(Entity::UpdatePhysicsHook, Coll); i switched to the update physics hook to emulate what is in the linked thread and still getting the fallowing error "cannot initialize a paramater of type 'void *' with an lvalue of type 'void (Leadwerks::Entity *)' Quote 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! Link to comment Share on other sites More sharing options...
Furbolg Posted April 1, 2013 Share Posted April 1, 2013 Try this one (not tested) void Coll(void* data) { Entity* ent = reinterpret_cast<Entity*>(data); ent->somemethod(); } this->Full->AddHook(Entity::UpdatePhysicsHook, Coll); Quote Link to comment Share on other sites More sharing options...
Josh Posted April 1, 2013 Share Posted April 1, 2013 I always just considered Try this one (not tested) void Coll(void* data) { Entity* ent = reinterpret_cast<Entity*>(data); ent->somemethod(); } this->Full->AddHook(Entity::UpdatePhysicsHook, Coll); Do NOT do this or you will mess up the call stack! I always just considered void* to be a generic pointer with no type. If the function doesn't accept your function, you should be able to just cast it to (void*) and it should work. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Furbolg Posted April 1, 2013 Share Posted April 1, 2013 Sorry josh but this statement is wrong and (void*) is a c cast, the code above is cleaner. Passing data as void* and cast it back is valid and sometimes you dont have a choice, for example most winapi functions do it this way (beginthread, getwindowlong ...). // Edit: your example compiles fine at my solution (picture attached) this is what i got in my CPP file void Coll(Entity* entity0)//, Entity* entity1, float* position, float* normal, float speed) { } this->Full->AddHook(Entity::UpdatePhysicsHook, Coll); i switched to the update physics hook to emulate what is in the linked thread and still getting the fallowing error "cannot initialize a paramater of type 'void *' with an lvalue of type 'void (Leadwerks::Entity *)' // Edit2: Oh sorry.. OSX... didnt see that But (void*) is still a bad choice Quote Link to comment Share on other sites More sharing options...
xtreampb Posted April 1, 2013 Author Share Posted April 1, 2013 so is this an OSX bug that josh needs to fix and i need to wait on or what? Also i have seen a bunch of different things (maybe it is all the same but i can't tell). What should I do? can anyone post a working work around with my code until the bug is fixed please. Lastly do i need to report this as a bug in the bug reporting section? Quote 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! Link to comment Share on other sites More sharing options...
Furbolg Posted April 1, 2013 Share Posted April 1, 2013 You can try the code i posted first... does OSX uses gcc ? Maybe you can update your compiler ? No it looks like a incompatibility .... c++ isnt that much standardized as i would wish (Visual C++ 6 anyone ? ). Quote Link to comment Share on other sites More sharing options...
Admin Posted April 1, 2013 Share Posted April 1, 2013 If you post a full example we can then correct your code. Quote Link to comment Share on other sites More sharing options...
xtreampb Posted April 1, 2013 Author Share Posted April 1, 2013 so yea didn't work, wouldn't compile. Yes OS X uses GCC. So i did some funny things. I'm not even sure what i did but this compiles... void (*Coll)//, Entity* entity1, float* position, float* normal, float speed) { }; this->Full->AddHook(Entity::UpdatePhysicsHook, Coll); however when the add hook is hit durring runtime it throws the following error EXC_BAD_ACCESS(code=2, address=0x0) So I have this pointer of a function that isn't initialized. So now i need to initialize my Coll function some how I believe. Can some one explain to me what i have done? Per your requested admin. My code as it stands now. my cpp file #include "Stone.h" #define MODEL_FOLDER "Models/Stone/" //Collisions Function void (*Coll)//, Entity* entity1, float* position, float* normal, float speed) { }; /*void mColl() { }*/ Stone::Stone() { this->Create(); } Stone::~Stone() { this->Release(); } void Stone::Create() { //load the models this->Full=Model::Load(MODEL_FOLDER + string("stone_1.mdl")); this->P1=Model::Load(MODEL_FOLDER + string("stone_1part01.mdl")); this->P2=Model::Load(MODEL_FOLDER + string("stone_1part02.mdl")); this->P3=Model::Load(MODEL_FOLDER + string("stone_1part03.mdl")); this->P4=Model::Load(MODEL_FOLDER + string("stone_1part04.mdl")); this->P5=Model::Load(MODEL_FOLDER + string("stone_1part05.mdl")); //this->Full->AddHook(<#const int hookid#>, <#void *hook#>); this->Full->AddHook(Entity::UpdatePhysicsHook, Coll); //set the phy shapes this->Full->SetShape(Shape::Load(MODEL_FOLDER + string("stone_1.phy"))); //this->P1->SetShape(Shape::Load(MODEL_FOLDER + string("stone_1part01.phy"))); //this->P2->SetShape(Shape::Load(MODEL_FOLDER + string("stone_1part02.phy"))); //this->P3->SetShape(Shape::Load(MODEL_FOLDER + string("stone_1part03.phy"))); //this->P4->SetShape(Shape::Load(MODEL_FOLDER + string("stone_1part04.phy"))); //this->P5->SetShape(Shape::Load(MODEL_FOLDER + string("stone_1part05.phy"))); //set the mass this->Full->SetMass(1); this->P1->SetMass(1); this->P2->SetMass(1); this->P3->SetMass(1); this->P4->SetMass(1); this->P5->SetMass(1); //hide the broken pieces this->P1->Hide(); this->P2->Hide(); this->P3->Hide(); this->P4->Hide(); this->P5->Hide(); } unsigned long Stone::Release() { this->Full->Release(); this->P1->Release(); this->P2->Release(); this->P3->Release(); this->P4->Release(); this->P5->Release(); return 0; } void Stone::SetPosition(Vec3 mPos) { this->Full->SetPosition(mPos); this->P1->SetPosition(mPos); this->P2->SetPosition(mPos); this->P3->SetPosition(mPos); this->P4->SetPosition(mPos); this->P5->SetPosition(mPos); } void Stone::SetRotation(Vec3 mRot) { this->Full->SetRotation(mRot); this->P1->SetRotation(mRot); this->P2->SetRotation(mRot); this->P3->SetRotation(mRot); this->P4->SetRotation(mRot); this->P5->SetRotation(mRot); } void Stone::Break()//Entity* entity0, Entity* entity1, float* position, float* normal, float speed) { this->Full->Hide(); this->P1->Show(); this->P2->Show(); this->P3->Show(); this->P4->Show(); this->P5->Show(); } my .h code #include "Leadwerks.h" using namespace Leadwerks; #ifndef Kings_Stone_h #define Kings_Stone_h class Stone { public: Stone(); ~Stone(); void Create();//leadwerks constructor unsigned long Release();//leadwerks deconstructor void SetPosition(Vec3); void SetRotation(Vec3); void Break(); //void __cdecl Break();//Entity* entity0, Entity* entity1, float* position, float* normal, float speed); private: //the models Model *Full; Model *P1; Model *P2; Model *P3; Model *P4; Model *P5; }; #endif Quote 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! Link to comment Share on other sites More sharing options...
MCP Posted April 1, 2013 Share Posted April 1, 2013 Read my post in this thread for cause and solution... http://www.leadwerks...atephysicshook/ Quote "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 More sharing options...
xtreampb Posted April 1, 2013 Author Share Posted April 1, 2013 so if type casting a void pointer to a function...how do i do that. I tried static_cast, dynamic_cast and reinterpret_cast. Also the implicit casts didn't work. Quote 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! Link to comment Share on other sites More sharing options...
MCP Posted April 1, 2013 Share Posted April 1, 2013 It's generally bad practice to cast a function pointer to anything let alone a void pointer which is why your compilers are complaining. They either don't allow it or if they do it can lead to all kinds of instability errors. The error is in the function declaration of AddHook(...) which wrongly expects you to pass a function pointer as a void pointer. It's a bug and there's nothing anyone can do until Josh fixes the issue. Quote "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 More sharing options...
Admin Posted April 2, 2013 Share Posted April 2, 2013 It's generally bad practice to cast a function pointer to anything let alone a void pointer which is why your compilers are complaining. They either don't allow it or if they do it can lead to all kinds of instability errors. The error is in the function declaration of AddHook(...) which wrongly expects you to pass a function pointer as a void pointer. It's a bug and there's nothing anyone can do until Josh fixes the issue. What data type would you suggest, and exactly what kind of errors are you describing? I don't see anything wrong with casting to a void*, it's just a pointer that takes either 32 or 64 bits of data. Quote Link to comment Share on other sites More sharing options...
xtreampb Posted April 2, 2013 Author Share Posted April 2, 2013 I just fallowed the updated tutorial that the admin linked to me in a chat (found here: http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/object/objectaddhook-r759) It compiles, but at run time throws the fallowing error: EXC_BAD_ACCESS(code=2, address=0x0) Anyone got any advice from here? Quote 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! Link to comment Share on other sites More sharing options...
Recommended Posts
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.