Shard Posted May 28, 2010 Share Posted May 28, 2010 For our trigger system I have created a fairly straight forward method. A trigger object hold all the values that we need, like speech, music, scripts, etc. I set the collision callback and when I collide it goes off successfully and correctly. However the player is still colliding with it, causing it to go off again. And again. And again. So I figured that I would free the collision body so that collision callback wouldn't occur. This leads to a new problem: the collision callback still occurs but all GetEntityUserData returns garbage and the trigger still tries to activate with garbage data resulting in an error. How do I stop collision callback once I'm done with it? //Trigger struct Trigger { TVec3 pos; TSound music; TSound *speech; string scene; TBody body; static Level *level; int usable; int characterLoadID; Trigger() { this->music = NULL; this->speech = NULL; usable = 1; } }; //Init Trigger *trigger = new Trigger; trigger->pos = objectPosition; //Music if(music != "") { music = "abstract::" + music; //trigger->music = new TSound; //(*trigger->music) = LoadSound(str(music.c_str())); trigger->music = LoadSound(str(music.c_str())); } //Body TVec6 box = GetEntityAABB(entity); float depth = box.Z1 - box.Z0; float height = box.Y1 - box.Y0; float width = box.X1 - box.X0; trigger->body = CreateBodyBox(width,height,depth); PositionEntity(trigger->body,objectPosition); RotateEntity(trigger->body,objectRotation); EntityType(trigger->body,4); SetEntityUserData(trigger->body,(byte*)trigger); //Data type to trigger SetEntityCallback(trigger->body,(byte*)TriggerCollision,ENTITYCALLBACK_COLLISION); //Collision callback function trigger->level = this->level; //Collision Callback void _stdcall TriggerCollision( TEntity triggerBody, TEntity entity, byte* position, byte* normal, byte* force, flt speed ) { if(GetEntityType(entity) == 1) { Trigger *trigger = (Trigger*) GetEntityUserData(triggerBody); trigger->level->ActivateTrigger(*trigger); } } //Level::ActivateTrigger void Level::ActivateTrigger(Trigger &trigger) { if(trigger.usable > 0) { if(trigger.music != NULL) PlaySound(trigger.music); //Music HideEntity(trigger.body); //Not working FreeEntity(trigger.body); //Not working trigger.usable--; } } Also, this thread should probably be moved to the C++ forums. >,> Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
ZioRed Posted May 28, 2010 Share Posted May 28, 2010 Have you tried to free the trigger in the callback? void _stdcall TriggerCollision( TEntity triggerBody, TEntity entity, byte* position, byte* normal, byte* force, flt speed ) { if(GetEntityType(entity) == 1) { Trigger *trigger = (Trigger*) GetEntityUserData(triggerBody); trigger->level->ActivateTrigger(*trigger); delete trigger; } } The FreeEntityCallback example on wiki do it. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Pixel Perfect Posted May 28, 2010 Share Posted May 28, 2010 As you don't control the code that fires the collisions I'd simply ignore all subsequent calls to that trigger once it's been fired within a set period of time or whilst the colliding entity remains the same. Then free the collisionBody if it's no longer required or leave it for the next collision. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
ArBuZ Posted May 28, 2010 Share Posted May 28, 2010 I didnt understand your problem in detail, but SetEntityCallback(entity,NULL,ENTITYCALLBACK_COLLISION) - disables callback. Quote Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64 3ds max / photoshop CS3 / C++ http://www.arbuznikov.com Link to comment Share on other sites More sharing options...
Pixel Perfect Posted May 28, 2010 Share Posted May 28, 2010 Handy to know ... cheers ArBuZ Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
Shard Posted May 29, 2010 Author Share Posted May 29, 2010 Have you tried to free the trigger in the callback? void _stdcall TriggerCollision( TEntity triggerBody, TEntity entity, byte* position, byte* normal, byte* force, flt speed ) { if(GetEntityType(entity) == 1) { Trigger *trigger = (Trigger*) GetEntityUserData(triggerBody); trigger->level->ActivateTrigger(*trigger); delete trigger; } } The FreeEntityCallback example on wiki do it. As you don't control the code that fires the collisions I'd simply ignore all subsequent calls to that trigger once it's been fired within a set period of time or whilst the colliding entity remains the same. Then free the collisionBody if it's no longer required or leave it for the next collision. I didnt understand your problem in detail, but SetEntityCallback(entity,NULL,ENTITYCALLBACK_COLLISION) - disables callback. Thanks. I tried all of these but none of them worked. Basically the code break to here in leoFramework.h inline void Framework::Update() const { ::leUpdateFramework(); //Here } Saying: Unhandled exception at 0x005c5e30 in Zero Hour.exe: 0xC0000005: Access violation reading location 0x003d0000. Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
Shard Posted May 31, 2010 Author Share Posted May 31, 2010 Thanks. I tried all of these but none of them worked. Basically the code break to here in leoFramework.h inline void Framework::Update() const { ::leUpdateFramework(); //Here } Saying: In the disassembly it breaks to here: 00424953 mov esi,esp 00424955 call dword ptr [leUpdateFramework (47E708h)] 0042495B cmp esi,esp 0042495D call @ILT+15255(__RTC_CheckEsp) (3C2B9Ch) I don't believe that this is because of multiple callbacks anymore. The callback isn't called again, this error happens as soon as it breaks out of the loop. Can someone with source code please test this out and tell me what is going on? Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
Laurens Posted May 31, 2010 Share Posted May 31, 2010 Hi Shard, Your last post makes me believe you are experiencing the bug I reported earlier. http://leadwerks.com/werkspace/index.php?/tracker/issue-59-crash-on-updateframework-when-using-callbacks/ EDIT: Josh had already solved it yesterday and I confirmed it is now working as it should. Most likely if you upgrade yours will be to. Quote Link to comment Share on other sites More sharing options...
Shard Posted May 31, 2010 Author Share Posted May 31, 2010 Hi Shard, Your last post makes me believe you are experiencing the bug I reported earlier. http://leadwerks.com/werkspace/index.php?/tracker/issue-59-crash-on-updateframework-when-using-callbacks/ EDIT: Josh had already solved it yesterday and I confirmed it is now working as it should. Most likely if you upgrade yours will be to. Thanks a butt load. Its still not working =O I just downloaded R5 and updated it and copied over the dll and it still breaks at the same point. What do? The update for r4 works but not for r5 so I assume that the dll for r5 needs to be updated. Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
ArBuZ Posted May 31, 2010 Share Posted May 31, 2010 Im not sure but try to pass pointer to void Level::ActivateTrigger(Trigger &trigger) function. void Level::ActivateTrigger(Trigger *trigger) and in the function use -> Quote Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64 3ds max / photoshop CS3 / C++ http://www.arbuznikov.com Link to comment Share on other sites More sharing options...
Laurens Posted May 31, 2010 Share Posted May 31, 2010 Have you used the update tool (Tools/Update.exe)? I experienced the bug in r5 aswell until I ran the updater. 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.