Laurens Posted January 15, 2010 Share Posted January 15, 2010 Hi, Could someone please give me an example of how to create a callback using LEO? I currently have the following (non-functional) code: ball.cpp ball.SetCallback((byte*)paddle->EntityCollisionCallback, ENTITYCALLBACK_COLLISION); paddle.h void EntityCollisionCallback(TEntity source, TEntity destination, byte* position, byte* normal, byte* force, float speed); Thanks! Quote Link to comment Share on other sites More sharing options...
Rick Posted January 15, 2010 Share Posted January 15, 2010 Is paddle->EntityCollisionCallbackdefined as static? Quote Link to comment Share on other sites More sharing options...
Laurens Posted January 15, 2010 Author Share Posted January 15, 2010 Is paddle->EntityCollisionCallbackdefined as static? No, it's an instance. I had hoped I could pull that off using LEO but since you're asking I guess I should implement the callback "plain old" C-style? Quote Link to comment Share on other sites More sharing options...
Rick Posted January 15, 2010 Share Posted January 15, 2010 Since LEO is just a wrapper for LE, at it's core it's still uses LE's function to setup callbacks. It sucks, I know. I have a way to map these to class members but it's probably just as easy to use the C style. Even the mapping way is done with the normal C callback, but inside that callback you map it back to the class function to call. Would have been cooler if LEO did that automatically. Quote Link to comment Share on other sites More sharing options...
Laurens Posted January 15, 2010 Author Share Posted January 15, 2010 Well my code compiles now. A new issue has risen though. My code now looks like this: ball.cpp ball.SetCallback((byte*)Paddle::EntityCollisionCallback, ENTITYCALLBACK_COLLISION); paddle.cpp void _stdcall Paddle::EntityCollisionCallback(TEntity source, TEntity destination, byte* position, byte* normal, byte* force, float speed) { int type = GetEntityType(source); } The method is declared static in the header of the Paddle class. When I run it, it detects a collision, calls the callback method between 8 to 16 times (approximately) (10 runs) without updating or rendering in between, and then craps out on framework.Update(), giving me an AccessViolationException. Any idea what's going on here? Quote Link to comment Share on other sites More sharing options...
Rick Posted January 15, 2010 Share Posted January 15, 2010 So if you remove the part that assigns this as a callback the framework Update() method doesn't give an error? The paddle or ball doesn't get destroyed at any point in this? Quote Link to comment Share on other sites More sharing options...
Laurens Posted January 15, 2010 Author Share Posted January 15, 2010 If I comment out the ball.SetCallback((byte*)Paddle::EntityCollisionCallback, ENTITYCALLBACK_COLLISION); part, than everything runs perfectly fine. The paddle nor the ball gets destroyed at any point. If I set a breakpoint in the callback function, all variables also get properly set. No bad pointers whatsoever. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 15, 2010 Share Posted January 15, 2010 Try replacing the function with just a normal C function once and see if that helps. Just for testing. Quote Link to comment Share on other sites More sharing options...
Laurens Posted January 15, 2010 Author Share Posted January 15, 2010 Replacing the LEO function with the normal C function does not change it. I even replaced all LEO structures with the standard C structures and yet the problem persists EDIT: Replacing framework.Update() with UpdateWorld() fixes the issue. I suppose this does lead to other problems since I am using Framework to render. Putting it on the tracker. Quote 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.