Revision: 8598 http://playerstage.svn.sourceforge.net/playerstage/?rev=8598&view=rev Author: hsujohnhsu Date: 2010-03-22 21:59:24 +0000 (Mon, 22 Mar 2010)
Log Message: ----------- This stemmed from trying start the world paused (-u) with dynamically spawned models. The model->Init() call does not need to be done when Loading through World::Load() but needs to be done when calling through ProcessEntitiesToLoad(). Here are the fixes: * moved pause to after init in main.cc * add a bool flag "initModel" to LoadEntities/LoadModel. Modified Paths: -------------- code/gazebo/trunk/server/World.cc code/gazebo/trunk/server/World.hh code/gazebo/trunk/server/main.cc Modified: code/gazebo/trunk/server/World.cc =================================================================== --- code/gazebo/trunk/server/World.cc 2010-03-20 02:22:39 UTC (rev 8597) +++ code/gazebo/trunk/server/World.cc 2010-03-22 21:59:24 UTC (rev 8598) @@ -209,7 +209,9 @@ gzthrow("Unable to create physics engine\n"); } - this->LoadEntities(rootNode, NULL, false); + // last bool is initModel, init model is not needed as Init() + // is called separately from main.cc + this->LoadEntities(rootNode, NULL, false, false); /*std::vector<Model*>::iterator miter; for (miter = this->models.begin(); miter != this->models.end(); miter++) @@ -441,7 +443,7 @@ /////////////////////////////////////////////////////////////////////////////// // Load a model -void World::LoadEntities(XMLConfigNode *node, Model *parent, bool removeDuplicate) +void World::LoadEntities(XMLConfigNode *node, Model *parent, bool removeDuplicate, bool initModel) { XMLConfigNode *cnode; Model *model = NULL; @@ -451,7 +453,7 @@ // Check for model nodes if (node->GetNSPrefix() == "model") { - model = this->LoadModel(node, parent, removeDuplicate); + model = this->LoadModel(node, parent, removeDuplicate, initModel); this->addEntitySignal(model); } } @@ -459,7 +461,7 @@ // Load children for (cnode = node->GetChild(); cnode != NULL; cnode = cnode->GetNext()) { - this->LoadEntities( cnode, model, removeDuplicate ); + this->LoadEntities( cnode, model, removeDuplicate, initModel); } } @@ -501,7 +503,8 @@ continue; } - this->LoadEntities( xmlConfig->GetRootNode(), NULL, true); + // last bool is initModel, yes, init model after loading it + this->LoadEntities( xmlConfig->GetRootNode(), NULL, true, true); delete xmlConfig; } this->toLoadEntities.clear(); @@ -554,7 +557,7 @@ //////////////////////////////////////////////////////////////////////////////// // Load a model -Model *World::LoadModel(XMLConfigNode *node, Model *parent, bool removeDuplicate) +Model *World::LoadModel(XMLConfigNode *node, Model *parent, bool removeDuplicate, bool initModel) { Pose3d pose; Model *model = new Model(parent); @@ -569,8 +572,14 @@ // Add the model to our list this->models.push_back(model); - if (Simulator::Instance()->GetSimTime() > 0) - model->Init(); + // If calling LoadEntity()->LoadModel()from Simulator::Load()->World::Load() + // GetWorldInitialized() is false, in this case, model->Init() is + // called later directly from main.cc through Simulator::Init() + // on the other hand + // LoadEntity()->LoadModel() is also called from ProcessEntitesToLoad(), + // in this case, GetWorldInitialized should return true, and we want + // to call model->Init() here + if (initModel) model->Init(); if (parent != NULL) model->Attach(node->GetChild("attach")); Modified: code/gazebo/trunk/server/World.hh =================================================================== --- code/gazebo/trunk/server/World.hh 2010-03-20 02:22:39 UTC (rev 8597) +++ code/gazebo/trunk/server/World.hh 2010-03-22 21:59:24 UTC (rev 8598) @@ -138,7 +138,7 @@ /// \param parent Parent of the model to load /// \param removeDuplicate Remove existing model of same name public: void LoadEntities(XMLConfigNode *node, Model *parent, - bool removeDuplicate); + bool removeDuplicate,bool initModel); /// \brief Insert an entity into the world. This function pushes the model // (encoded as an XML string) onto a list. The Graphics Thread will then @@ -252,7 +252,7 @@ /// \param parent The parent model /// \param removeDuplicate Remove existing model of same name /// \return The model that was created - private: Model *LoadModel(XMLConfigNode *node, Model *parent, bool removeDuplicate); + private: Model *LoadModel(XMLConfigNode *node, Model *parent, bool removeDuplicate,bool initModel); /// \brief Set the model pose and the pose of it's attached children /// \param model The model to set Modified: code/gazebo/trunk/server/main.cc =================================================================== --- code/gazebo/trunk/server/main.cc 2010-03-20 02:22:39 UTC (rev 8597) +++ code/gazebo/trunk/server/main.cc 2010-03-22 21:59:24 UTC (rev 8598) @@ -279,7 +279,6 @@ gazebo::Simulator::Instance()->Load(worldFileName, optServerId); gazebo::Simulator::Instance()->SetTimeout(optTimeout); gazebo::Simulator::Instance()->SetPhysicsEnabled(optPhysicsEnabled); - gazebo::Simulator::Instance()->SetPaused(optPaused); } catch (gazebo::GazeboError e) { @@ -293,6 +292,7 @@ try { gazebo::Simulator::Instance()->Init(); + gazebo::Simulator::Instance()->SetPaused(optPaused); } catch (gazebo::GazeboError e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit