Commits

John Hsu committed 4d61a58 Merge

merging from default

  • Participants
  • Parent commits 75ad2e0, 4890606
  • Branches move_static_collision

Comments (0)

Files changed (4)

gazebo/physics/Model.cc

   this->AddType(MODEL);
   this->updateMutex = new boost::recursive_mutex();
   this->jointController = NULL;
+  this->pluginsLoaded = false;
 }
 
 //////////////////////////////////////////////////
   if (_sdf->HasElement("link"))
   {
     sdf::ElementPtr linkElem = _sdf->GetElement("link");
-    bool first = true;
+    bool canonical_link_initialized = false;
     while (linkElem)
     {
       // Create a new link
       // FIXME: canonical link is hardcoded to the first link.
       //        warn users for now, need  to add parsing of
       //        the canonical tag in sdf
-      if (first)
+      if (!canonical_link_initialized)
       {
         link->SetCanonicalLink(true);
         this->canonicalLink = link;
-        first = false;
+        canonical_link_initialized = true;
       }
 
       // Load the link using the config node. This also loads all of the
 {
   this->updateMutex->lock();
 
+  /// Load plugins for this model once
+  /// @todo: john: this works fine, but we should add a regression test
+  /// to make sure there is no race condition.
+  if (!this->pluginsLoaded)
+  {
+    this->LoadPlugins();
+    this->pluginsLoaded = true;
+  }
+
   if (this->jointController)
     this->jointController->Update();
 

gazebo/physics/Model.hh

       private: boost::recursive_mutex *updateMutex;
       private: JointController *jointController;
 
+      private: bool pluginsLoaded;
+
       /// used by Model::AttachStaticModel
       protected: std::vector<ModelPtr> attachedModels;
 

gazebo/physics/World.cc

   this->pause = false;
   this->thread = NULL;
 
+  this->pluginsLoaded = false;
+
   this->name = _name;
 
   this->needsReset = false;
 //////////////////////////////////////////////////
 void World::Update()
 {
-  static bool first = true;
-
-
-  /// Plugins that manipulate joints (and probably other properties) require
-  /// one iteration of the physics engine. Do not remove this.
-  if (first)
-  {
-    this->physicsEngine->UpdatePhysics();
-    this->LoadPlugins();
-    first = false;
-    return;
-  }
-
   if (this->needsReset)
   {
     if (this->resetAll)
 
     this->physicsEngine->UpdatePhysics();
 
+    /// need this because ODE does not call dxReallocateWorldProcessContext()
+    /// until dWorld.*Step
+    /// Plugins that manipulate joints (and probably other properties) require
+    /// one iteration of the physics engine. Do not remove this.
+    if (!this->pluginsLoaded)
+    {
+      this->LoadPlugins();
+      this->pluginsLoaded = true;
+    }
+
     // do this after physics update as
     //   ode --> MoveCallback sets the dirtyPoses
     //           and we need to propagate it into Entity::worldPose
 //////////////////////////////////////////////////
 void World::LoadPlugins()
 {
-  for (unsigned int i = 0; i < this->rootElement->GetChildCount(); i++)
-  {
-    if (boost::shared_dynamic_cast<Model>(this->rootElement->GetChild(i)))
-    {
-      boost::shared_dynamic_cast<Model>(
-          this->rootElement->GetChild(i))->LoadPlugins();
-    }
-  }
-
   // Load the plugins
   if (this->sdf->HasElement("plugin"))
   {

gazebo/physics/World.hh

               { this->enablePhysicsEngine = _enable; }
 
       private: RayShapePtr testRay;
+      private: bool pluginsLoaded;
     };
 
     /// \}