dCustomTriggerManager Triggers permanently

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

dCustomTriggerManager Triggers permanently

Postby Lax » Tue May 07, 2019 9:39 am

Hi,

I'm using the dCustomTriggerManager to react, when a body enters the trigger, to react on events:

- OnEnter
- OnExit
- OnInside

The strange thing is that OnEnter and OnExit is triggered permanently alternatingly when the body is inside the trigger. I though, that onEnter is just triggered when the body enters the trigger once and onExit, when the body leaves the trigger once. Just OnInside should trigger permanently.

Is this a bug? I orientated on the newton examples.

Best Regards
Lax
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: dCustomTriggerManager Triggers permanently

Postby Julio Jerez » Tue May 07, 2019 10:08 am

If happens it is a bug.
Does it happens in the sandbox demo?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomTriggerManager Triggers permanently

Postby Lax » Tue May 07, 2019 4:30 pm

Hard to say, because as I see trigger is only used in advanced player controller, but the code is deactivated. But when I start advanced player controller, the demo will crash after a few seconds.
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: dCustomTriggerManager Triggers permanently

Postby Julio Jerez » Tue May 07, 2019 4:59 pm

The buoyancy uses thrigger for the swimming pool
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomTriggerManager Triggers permanently

Postby Julio Jerez » Tue May 07, 2019 6:02 pm

I just committed the buoyancy test with one ball,
and it prints a message when the ball enter, is inside and exit the big box in the middle.
It seems to work fine.

I see how having one callback with an even code can be confusing, so I made simple by having three separate callback than you can implement optionally.
the base class is like this now

Code: Select all
virtual void OnEnter (const dCustomTriggerController* const me, NewtonBody* const guess) const
virtual void OnExit (const dCustomTriggerController* const me, NewtonBody* const guess) const
virtual void WhileIn (const dCustomTriggerController* const me, NewtonBody* const guess) const


I hope this should make easier to use.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomTriggerManager Triggers permanently

Postby Lax » Sat May 11, 2019 1:31 pm

Thats strange, because when I debug the newton code, I see that in:
Code: Select all
dCustomTriggerManager::UpdateTrigger

The 'controller->m_manifest' has always 0 items, so that the node cannot be found and hence
Code: Select all
EventCallback (controller, m_enterTrigger, cargoBody);
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: dCustomTriggerManager Triggers permanently

Postby Julio Jerez » Sat May 11, 2019 2:51 pm

I think you are tryin to test an older version that might have a bug.

the interface is no much simpler

Code: Select all
class dCustomTriggerManager: public dCustomParallelListener
{
   public:
   CUSTOM_JOINTS_API dCustomTriggerManager (NewtonWorld* const world);
   CUSTOM_JOINTS_API virtual ~dCustomTriggerManager();
   
   CUSTOM_JOINTS_API virtual dCustomTriggerController* CreateTrigger (const dMatrix& matrix, NewtonCollision* const convexShape, void* const userData);
   CUSTOM_JOINTS_API virtual void DestroyTrigger (dCustomTriggerController* const trigger);

   virtual void OnEnter (const dCustomTriggerController* const me, NewtonBody* const guess) const {}
   virtual void OnExit (const dCustomTriggerController* const me, NewtonBody* const guess) const {}
   virtual void WhileIn (const dCustomTriggerController* const me, NewtonBody* const guess) const {}

   dList<dCustomTriggerController>& GetControllersList () {return m_triggerList;}
   const dList<dCustomTriggerController>& GetControllersList () const {return m_triggerList;}


you just implement any of those method is you subclass and you get the proper call.
I test it with the buoyancy and seems to work.

edit:
I just added an optimization that can make eassy for you to debug and see what is doing.
if you set a break point on function
void dCustomTriggerManager::PreUpdate(dFloat timestep)

you will see the logic follows these three states for each body that is inside a trigger.
Code: Select all
if (first time in trigger)
  set lru
  call OnEnter
else if (is in trigger){
   update lru
   call whileIn
}
if (lru was not updated)
  call OnExit
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomTriggerManager Triggers permanently

Postby Lax » Mon May 13, 2019 12:38 pm

Hi,

oh ok, "dCustomParallelListener". Where can I get the new newton system?

Regards
Lax
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: dCustomTriggerManager Triggers permanently

Postby Julio Jerez » Mon May 13, 2019 1:43 pm

Lax wrote:oh ok, "dCustomParallelListener". Where can I get the new newton system?

I do not understand that question, can you rephrase it?

The class you subclass from in the dCustomThigger, which derived from parallel listener.
The you just implement those three methods.
If all of the triggered system I have seem this is the simpler to user, in my opinion. It should not be that difficult.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomTriggerManager Triggers permanently

Postby Lax » Mon May 13, 2019 2:31 pm

I'm sorry, I did not see, that dCustomParallelListener is part of the newest newton revision.
I will try it, thanks.
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: dCustomTriggerManager Triggers permanently

Postby Julio Jerez » Mon May 13, 2019 4:00 pm

you need to get the latest update form time to time so that the questions make more sense.
or else I will be give answers that make no sense either.

I undestand not to keep with the latest and make hot fixed, but if you let is go to far behind the I am confused and we talk pass each other. :D
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomTriggerManager Triggers permanently

Postby Lax » Fri Jun 14, 2019 4:17 pm

Yes I'm sorry, you are right. Its hard to remain updated, with all kind of topics.
The new trigger does nevertheless update permanently on "OnEnter" event. I need to find out, why that does happen, when I have the time.

Best Regards
Lax
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: dCustomTriggerManager Triggers permanently

Postby Lax » Wed Jun 19, 2019 12:19 pm

I debugged AlchimedesBuoyancy demo, and it works correctly. So I do not know why it is not working at my side:(

I see that after OnEnter, OnExit is each time called, because the m_manifest has no nodes.
It happens because of the code in the PreUpdateFunction:
Code: Select all
for (dList<dCustomTriggerController>::dListNode* node = GetControllersList().GetFirst(); node; node = node->GetNext()) {
      dCustomTriggerController* const controller = &node->GetInfo();
      dCustomTriggerController::dTriggerManifest::Iterator iter(controller->m_manifest);

      for (iter.Begin(); iter;) {
         dCustomTriggerController::dTriggerManifest::dTreeNode* const node = iter.GetNode();
         iter++;
         if (node->GetInfo() != m_lru) {
            NewtonBody* const cargoBody = node->GetKey();
            OnExit(controller, cargoBody);

            dCustomScopeLock lock(&m_lock);
            controller->m_manifest.Remove(cargoBody);
         }
      }
   }

Where:
Code: Select all
if (node->GetInfo() != m_lru) {

the id is always unequal. E.g. "m_lru" is: 1059 and "node->GetInfo()" is 1058. How can that happen?
I have just one trigger and one body, that enters the trigger.

Best Regards
Lax
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Re: dCustomTriggerManager Triggers permanently

Postby Julio Jerez » Wed Jun 19, 2019 2:11 pm

ok the buoyancy may be to complex, I added a simpler repro that only place one trigger and one body.
It is set as the default demo now.

you can pick the solid box and drag it to the trigger and check the debug output
In my test enter is call once, the on trigger each frame while the body is in the trigger and exit is call once before exiting the trigger.

I think this is the simpler test I can think off, please see if ti work for you and maybe you can recreate the bug on that demo the demo is:
../../applications\demosSandbox\sdkDemos\demos\UsingNewtonMeshTool.cpp
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: dCustomTriggerManager Triggers permanently

Postby Lax » Thu Jun 20, 2019 10:04 am

Thanks for the easy demo. I debugged the demo and orientated for code creation. I found nothing suspicious. Your demo does work correctly. I also created a simple scenario on my side. I see that there are several thinks wrong, see the attached video:

http://www.lukas-kalinowski.com/Homepage/wp-content/uploads/Trigger.mp4
Often, the case does collide with the trigger container object. I do not know why. The collision hull is correct. Then after I while I could throw the case inside the container, but exit has been called.

What could that be?

Here is from my code side what I do:
Code: Select all
staticCollision = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision(this->ogreNewt, entity, true, 0));
this->physicsBody = new OgreNewt::TriggerBody(this->ogreNewt, this->gameObjectPtr->getSceneManager(), staticCollision,
               new PhysicsTriggerCallback(this->gameObjectPtr.get(), this->gameObjectPtr->getLuaScript()));

That is how I create the body.
In TriggerBody I create the trigger:
Code: Select all
CustomTriggerManager* triggerManager = m_world->getTriggerManager();

      if (nullptr != m_triggerController)
      {
         // ((dCustomTriggerManager*)m_triggerController)->DestroyTrigger(m_triggerController);
         triggerManager->DestroyTrigger(m_triggerController);
         m_triggerController = nullptr;
      }

      dFloat matrix[16];
      OgreNewt::Converters::QuatPosToMatrix(this->getOrientation(), this->getPosition(), matrix);

      m_triggerController = triggerManager->CreateTrigger(&matrix[0], col->getNewtonCollision(), /*m_triggerCallback*/nullptr);
      // m_body is the trigger body
      m_body = m_triggerController->GetBody();
      
      NewtonBodySetTransformCallback(m_body, newtonTransformCallback);

      NewtonBodySetUserData(m_body, this);
      
      NewtonDestroyCollision(col->getNewtonCollision());

      m_triggerController->SetUserData(m_triggerCallback);

CustomTriggerManager is this class:
Code: Select all
CustomTriggerManager::CustomTriggerManager(World* world)
      : dCustomTriggerManager(world->getNewtonWorld())
   {

   }

   void CustomTriggerManager::OnEnter(const dCustomTriggerController* const me, NewtonBody* const guess) const
   {
      TriggerCallback* const callback = (TriggerCallback*)me->GetUserData();
      const OgreNewt::Body* visitor = (const OgreNewt::Body*) NewtonBodyGetUserData(guess);
      callback->OnEnter(visitor);
      // m_world->criticalSectionLock();
   }

   void CustomTriggerManager::OnExit(const dCustomTriggerController* const me, NewtonBody* const guess) const
   {
      TriggerCallback* const callback = (TriggerCallback*)me->GetUserData();
      const OgreNewt::Body* visitor = (const OgreNewt::Body*) NewtonBodyGetUserData(guess);
      callback->OnExit(visitor);
   }

   void CustomTriggerManager::WhileIn(const dCustomTriggerController* const me, NewtonBody* const guess) const
   {
      TriggerCallback* const callback = (TriggerCallback*)me->GetUserData();
      const OgreNewt::Body* visitor = (const OgreNewt::Body*) NewtonBodyGetUserData(guess);
      callback->OnInside(visitor);
   }

   void CustomTriggerManager::DestroyTrigger(dCustomTriggerController* const trigger)
   {
      TriggerCallback* const userData = (TriggerCallback*)trigger->GetUserData();
      delete userData;
      dCustomTriggerManager::DestroyTrigger(trigger);
   }


CustomTriggerManager is created just once in OgreNewt_World:
Code: Select all
CustomTriggerManager* triggerManager = m_world->getTriggerManager();
-->
CustomTriggerManager* World::getTriggerManager(void)
{
      if (nullptr == m_triggerManager)
         m_triggerManager = new CustomTriggerManager(this);

      return m_triggerManager;
}


Best Regards
Lax
Please support SecondEarthTechnicBase built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd17-5ff5-40a0-ac6f-44b97b79be62
Image
Lax
 
Posts: 165
Joined: Sat Jan 08, 2011 8:24 am

Next

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 8 guests

cron