Rekindled Phoenix Posted March 27, 2010 Share Posted March 27, 2010 The delegates are included, so what is the best way to capture the collision events using the new Headers? Without the Headers using TylerH's old wrapper, I'd call SetEntityCallback like this: SetEntityCallback(box1, New EntityCallback(AddressOf DoSomething), ENTITYCALLBACK_COLLISION) With the new Headers, do I create something like this? If so, how do I tell Leadwerks to invoke the delegate without the SetEntityCallback function? //C# (translated, may be incorrect) EntityCollisionCallback del = new EntityCollisionCallback(CollisionHappened); public void CollisionHappened(System.IntPtr _entity1, System.IntPtr _entity2, Leadwerks.Vector3 _position, Leadwerks.Vector3 _normal, float force) { DrawText(_entity1, 300, 300); } EDIT: VB removed I can't find the 'SetEntityCallback' function in the Core namespace. Where did it go? Quote Link to comment Share on other sites More sharing options...
ZioRed Posted March 29, 2010 Share Posted March 29, 2010 It seems that they missed to add or expose a SetCallback method in the Entity class like the one exposed in the Material class. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
L B Posted March 29, 2010 Share Posted March 29, 2010 It seems that they missed to add or expose a SetCallback method in the Entity class like the one exposed in the Material class. Version 1.3 Implement delegates and callbacks. Sorry, not much time on my hands. Quote Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted March 30, 2010 Author Share Posted March 30, 2010 Would TylerH be able to handle this? It should be pretty easy right? Quote Link to comment Share on other sites More sharing options...
L B Posted March 30, 2010 Share Posted March 30, 2010 I could as well. I simply lost some interest, but mostly a lot of time to give to Leadwerks development. Klepto has proposed to do it, I will send him the source tonight. Then hopefully, he will send me his modifications and I'll be able to publish V.1.21. Quote Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted March 31, 2010 Author Share Posted March 31, 2010 That would be most helpful. Thank you Ubu. I looked in the old wrapper and found this as the only callback / event handler. Would this help? [DllImport(LEADWERKS_DLL, EntryPoint = "SetEntityCallback", CallingConvention = CallingConvention.StdCall)] public static extern void SetEntityCallback(IntPtr _entity, EntityCallback callback, int id); A separate boolean with a synclock surrounding it tells my render loop to display "Collisions Yay!". I get random crashes, after a series of them are displayed though, mostly when I'm not currently colliding with anything... EDIT: Added my code (VB) Dim KeepCallback As New EntityCallback(AddressOf test) SetEntityCallback(Player.Pointer, KeepCallback, EntityCallbackType.Collision) '//System.GC.KeepAlive(KeepCallback) After the first collision there's a timespan of a couple seconds with or without collisions, then the app crashes. *Investigating whyyyyyyy* Oh, and don't forget the function "FreeEntityCallback" !! Quote Link to comment Share on other sites More sharing options...
klepto2 Posted March 31, 2010 Share Posted March 31, 2010 Hi, I will start today to implement the missing functions (As long as i find everything) If someone is functions/delegates he/she is missing in the current release please post them here. So I'm able to better find the missing functions. Also I will add a Leadwerks Control and send it to Ubu, maybe he will add it to the main assemblies. @Rekindeled Phoenix: This needs some investigation, I remember that it works without issues in the old wrapper maybe something with the delegate definition is wrong. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted April 1, 2010 Author Share Posted April 1, 2010 @Klepto I used the same code from the original wrapper classes. Do you see anything wrong with my DLL declared function posted above? (Will post an example later for debugging) When calling the DLL's SetEntityCallback, the function only works when you set the type as a regular EntityCallback delegate. There are at least 6 other callbacks in the wrapper that can't be used! Why?? Can anyone else get callbacks to work without crashing their app? Quote Link to comment Share on other sites More sharing options...
klepto2 Posted April 1, 2010 Share Posted April 1, 2010 No, but I need to to investigate a bit further. If i remember correctly there was a need to Marshal the structs. Yesterday I wasn't able to solve it but hopefully i will solve everything over eastern weekend. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
klepto2 Posted April 1, 2010 Share Posted April 1, 2010 I'm still working on this issue, but for the meantime you can surround the UpdateWorld command with a Try Catch Block. Not elegant but it seems to work. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted April 2, 2010 Author Share Posted April 2, 2010 ...you can surround the UpdateWorld command with a Try Catch Block. Not elegant but it seems to work. Sounds like a good temporary alternative. Let me know when you've found a solution, it still crashes my game even with error handling. I'm still trying to figure what's causing the problem. EDIT: I can't get the method for FreeEntityCallback to work at all. Try catches seem to be useless as the Engine throws a System.ExecutionEngineException, which isn't caught for some reason. Quote Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted April 9, 2010 Author Share Posted April 9, 2010 So I've tried freeing the entity that checks the callback from LE and Windows memory and found that it delays the crash by about 10-30 seconds. Without removing the object, the application will crash after about 5 seconds, no matter what Garbage Collector settings are assigned to the object. It seems to crash out of the bounds of the App Domain. Whether the OpenGL Window Handle (Leadwerks) is crashing, or whether it's .Net Memory Management causing the issue, I still can't figure it out. Anyone else get collision working yet? Quote Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted July 3, 2010 Author Share Posted July 3, 2010 Even with implementing 'FreeEntityCallback', the LE unmanaged code frees and entity with a managed delegate, and my application crashes. How do I 'detach' the managed delegate from the object before the application frees the memory space?? With access to only the delegate / callback in managed code, how do I tell LE to remove the handler for that object so it doesn't crash my program? Could someone please update the headers, and if possible, provide a working code example? Quote Link to comment Share on other sites More sharing options...
TylerH Posted July 4, 2010 Share Posted July 4, 2010 If you grab the SVN and look at GameEntity.cs, it contains all of the Garbage Collection calls you need to prevent these crashes and safely free everything before being freed Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted July 5, 2010 Author Share Posted July 5, 2010 Thanks TylerH, I've found the GameEntity class and converted it to VB, and still am having issues. When the physics body 'AmmoBody' collides with the terrain, OnCollision() within the GameEntity object are fired and so is my DeclareCollisionToScreen() method. Though, the main thread never seems to return to the render loop, throwing an access violation exception. Here is my code: Is this the correct way of implementing collision detection using your GameEntity class? TylerH, could you provide a working example? VB 'Create a physics body Dim AmmoBody As Body = Body.CreateBox(0.2, 0.2, 0.2) 'Set it as a GameEntity class object Dim GameEntityObject As New GameEntity(AmmoBody.Pointer) 'Create handler to throw event Dim CollisionDelegate As New GameEntity.CollisionEventHandler(AddressOf DeclareCollisionToScreen) AddHandler GameEntityObject.Collision, CollisionDelegate 'Method that's fired Sub DeclareCollisionToScreen(ByVal Sender As Object, ByVal e As CollisionEventArgs) DrawText(e.Entity0.ToString, 50, 50) End Sub C# (Online converter) //Create a physics body Body AmmoBody = Body.CreateBox(0.2, 0.2, 0.2); //Set it as a GameEntity class object GameEntity GameEntityObject = new GameEntity(AmmoBody.Pointer); //Create handler to throw event GameEntity.CollisionEventHandler CollisionDelegate = new GameEntity.CollisionEventHandler(DeclareCollisionToScreen); GameEntityObject.Collision += CollisionDelegate; //is converter correct here? //Method that's fired public void DeclareCollisionToScreen(object Sender, CollisionEventArgs e) { DrawText(e.Entity0.ToString, 50, 50); } Quote Link to comment Share on other sites More sharing options...
ZioRed Posted July 5, 2010 Share Posted July 5, 2010 Found a problem and may be a solution: every call to the GameEntity events must check if the event has been assigned before calling it and must be commented the throw exception in the destructor. namespace Leadwerks.Game { public class GameEntity : Leadwerks.Entity, IDisposable { ...... ~GameEntity() { //throw new System.NotImplementedException(); } ...... protected virtual void OnFreeEntity(IntPtr entity) { if (FreeEntity != null) FreeEntity(this, entity); } } } With those changes to GameEntity I have no exception running the following VB code: Sub Main() Graphics.Initialize(800, 600) Framework.Initialize(False) Debug.Physics = True Collisions.Set(1, 1, True) Dim cube As Body = Body.CreateBox(1, 1, 1) cube.Mass = 1 cube.CollisionType = 1 Dim plane As Body = Body.CreateBox(10, 0.2, 10) plane.CollisionType = 1 plane.Position = cube.Position plane.Move(New Vector3(0, -1, 0)) Dim AmmoBody As Body = Body.CreateBox(1, 1, 1) AmmoBody.CollisionType = 1 AmmoBody.Mass = 1 AmmoBody.Position = cube.Position AmmoBody.Move(New Vector3(1.5, 0, 0)) Dim GameEntityObject As New GameEntity(AmmoBody.Pointer) AddHandler GameEntityObject.Collision, New CollisionEventHandler(AddressOf DeclareCollisionToScreen) While (Not Keyboard.KeyHit(Key.Escape) And Not Window.HasRequestedClose()) Framework.Update() Framework.Render() Graphics.Flip() End While Framework.Terminate() End Sub Sub DeclareCollisionToScreen(ByVal Sender As Object, ByVal e As CollisionEventArgs) Drawing.Text(e.Entity0.ToString, 50, 50) End Sub Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
TylerH Posted July 6, 2010 Share Posted July 6, 2010 I never implemented the destructor?! That would explain it Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted July 7, 2010 Author Share Posted July 7, 2010 That solves part of the problem. Thanks ZioRed Have you tried moving the object over 100 units away from the camera or waited 30 seconds after the collision occurs? The collision events work fine in my code, but now the object is culled or reallocated and ends up killing the process. Why would distance cause a problem?? Soon I'll compile a working demo, upgrade to VS2010, and update the C# Wrapper to 1.32.8 Quote Link to comment Share on other sites More sharing options...
ZioRed Posted July 7, 2010 Share Posted July 7, 2010 Have you tried moving the object over 100 units away from the camera or waited 30 seconds after the collision occurs? The collision events work fine in my code, but now the object is culled or reallocated and ends up killing the process. ... Soon I'll compile a working demo, upgrade to VS2010, and update the C# Wrapper to 1.32.8 Yes please, post a sample code (with VS2010 and the latest wrapper) to test, so I can test both in NET and in C. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com 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.