xtreampb Posted April 2, 2013 Author Share Posted April 2, 2013 per admin request here is my source code. my stone.cpp file where my issue is taking place void Coll (Entity* entity0)//, Entity* entity1, float* position, float* normal, float speed) { System::Print("Test"); } 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, (void*)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 stone.h file #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 and my App.cpp file #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } // #if defined (PLATFORM_WINDOWS) || defined (PLATFORM_MACOS) bool freelookmode=true; #else bool freelookmode=false; #endif bool App::Start() { //Create a window window = Window::Create("Kings"); //Create a context context = Context::Create(window); //Create a world world = World::Create(); //Create a camera camera = Camera::Create(); camera->Move(0,2,-5); camera->SetRotation(35,0,0); SpotLight *mLight=SpotLight::Create(); mLight->SetPosition(2,5,0); mLight->SetRange(10); mLight->SetColor(1.0, 1.0, 1.0); Stone *mStone=new Stone(); mStone->SetPosition(Vec3(0,10,0)); /*std::string mapname = System::GetProperty("map","Maps/Test.map"); Map::Load(mapname);*/ Model *ground=Model::Load("Models/CobbleBlock/Block_1.mdl"); ground->SetScale(10,.2,10); ground->SetPosition(0, -2, 0); ground->SetShape(Shape::Box()); mLight->Point(ground); //Hide the mouse cursor window->HideMouse(); //std::string mapname = System::GetProperty("map","Maps/start.map"); //Map::Load(mapname); //Move the mouse to the center of the screen window->SetMousePosition(context->GetWidth()/2,context->GetHeight()/2); return true; } bool App::Loop() { //Close the window to end the program if (window->Closed()) { return false; } //Press escape to end freelook mode if (window->KeyHit(Key::Escape)) { window->closed=true; } Time::Update(); world->Update(); world->Render(); context->Sync(false); return true; } 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 2, 2013 Share Posted April 2, 2013 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. ..and what makes you think function pointers are? I've already given you an example of how to fix your code in this thread (post #4)... http://www.leadwerks.com/werkspace/topic/6321-le3updatephysicshook/ If you want a more detailed explanation of what you can or can't do with function pointers refer this thread for a better insight... http://stackoverflow.com/questions/559581/casting-a-function-pointer-to-another-type 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 2, 2013 Author Share Posted April 2, 2013 your example in the other thread is how to fix the bug in the source code...I don't have access to the source code. Admin posted an updated source code doc saying that should work. it does compile, but it now has a runtime error with the characteristics of the pointer not being initialized. 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 2, 2013 Share Posted April 2, 2013 Apologies xtreampb, the code example was meant for Admin because the error is within LE3 source code not your code. The reason you're getting a runtime error now is because a function pointer for all intense purposes is not compatible with a void pointer so your code is trying to call a function at an invalid memory address. 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 ..and what makes you think function pointers are? What else would they be? It's just a memory address. Quote Link to comment Share on other sites More sharing options...
Rick Posted April 2, 2013 Share Posted April 2, 2013 I really wish you'd use something like http://www.leadwerks...le/367-c-event/ for this stuff so that we can use class functions for our callbacks. These are just templates so this code should port to any platform. All it's missing is a way to unregister a function. At some point I also had it so you could pass either a normal C function or a class function by overloading Bind() and firing any of both types in Raise(). LE3 is a C++ library now so there is no harm in doing this. 1 Quote Link to comment Share on other sites More sharing options...
Furbolg Posted April 2, 2013 Share Posted April 2, 2013 What else would they be? It's just a memory address. If you argue this way then let me ask: whats the difference between integer and string ? In theory (assembler) you are right josh but c++ has some patterns / behavior which define some basic rules. You can't just take the ones you like and ignore the rest. // Edit: LE3 is a C++ library now so there is no harm in doing this. To be honest, its actually more C/C++ then C++... dont take it personal, please. Quote Link to comment Share on other sites More sharing options...
Josh Posted April 2, 2013 Share Posted April 2, 2013 In theory (assembler) you are right josh but c++ has some patterns / behavior which define some basic rules. You can't just take the ones you like and ignore the rest. I'd like it if someone could explain what the problem is then. To be honest, its actually more C/C++ then C++... dont take it personal, please. NOW IT'S PERSONAL!!! Seriously, are people just being pedantic or is there really a problem? 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...
xtreampb Posted April 2, 2013 Author Share Posted April 2, 2013 Josh using the doc posted for object::addhook (link here http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/object/objectaddhook-r759). My code now compiles but throws the above mentioned runtime error. MPC says this error needs to be fixed in the LE3 source code for OS X b/c it apprently works for windows according to rick. 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 2, 2013 Share Posted April 2, 2013 Just try and post your statement in a c++ forum.... but take cover Is it a problem ? For c++ programmers (the guys who love c++ and not only use it because of speed/portability): yes For the big part of this community: probably not But you mentioned a messed up callstack, this can't be happening when used correct c++ patterns (mcp posted). // edit: Josh using the doc posted for object::addhook (link here http://www.leadwerks...ectaddhook-r759). My code now compiles but throws the above mentioned runtime error. MPC says this error needs to be fixed in the LE3 source code for OS X b/c it apprently works for windows according to rick. It is working but the behavior is undefined, it can work on windows but dont work on *nix. Quote Link to comment Share on other sites More sharing options...
Josh Posted April 2, 2013 Share Posted April 2, 2013 Josh using the doc posted for object::addhook (link here http://www.leadwerks...ectaddhook-r759). My code now compiles but throws the above mentioned runtime error. MPC says this error needs to be fixed in the LE3 source code for OS X b/c it apprently works for windows according to rick. What compiler are we talking about? It works in Xcode when I tried it. Your collision function here does not follow the function syntax, so I would expect errors: void Coll (Entity* entity0)//, Entity* entity1, float* position, float* normal, float speed) { System::Print("Test"); } 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...
Josh Posted April 2, 2013 Share Posted April 2, 2013 Are you saying using typedef can avoid problems if the user gets the function declaration wrong? 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 2, 2013 Share Posted April 2, 2013 Typedef is just a shorter form / comfort: (these example are from a dll (plugin system) and i dont put in c++ casts, they would make it harder to understand) Typedef: // define the type typedef int(__stdcall *CallBack)(void); // use it to load the method CallBack callme = (CallBack)::GetProcAddress(hDLL, "somecallback"); // call the method callme(); Without: // use it int(__stdcall *CallBack)(void) = 0; CallBack = (int(__stdcall*)(void))::GetProcAddress(hDLL, "somecallback"); // call it CallBack(); Quote Link to comment Share on other sites More sharing options...
Josh Posted April 2, 2013 Share Posted April 2, 2013 The function declaration for each different callback may be different. So there's no single declaration I can use for them. That's why they get cast to a pointer. 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 2, 2013 Share Posted April 2, 2013 I see your problem, its like you want to store int, float, double and std::string in a single std::vector. I dont have a solution right now, have you had a look at the c++ design patterns? Quote Link to comment Share on other sites More sharing options...
xtreampb Posted April 2, 2013 Author Share Posted April 2, 2013 What compiler are we talking about? It works in Xcode when I tried it. Your collision function here does not follow the function syntax, so I would expect errors: void Coll (Entity* entity0)//, Entity* entity1, float* position, float* normal, float speed) { System::Print("Test"); } Right now just trying to get it to work i'm using the update physics call back, just trying to get anything to work. Yes i'm using xCode. I am just a novice but would a union work for you josh, or how about the new C++ 2011 standard. There is a new data type "auto" that may work. just throwing some things out there... 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.