Changeset 10580 for code/branches/core7/src/orxonox
- Timestamp:
- Sep 12, 2015, 4:10:02 PM (9 years ago)
- Location:
- code/branches/core7/src/orxonox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/orxonox/Level.cc
r10579 r10580 35 35 #include "core/XMLFile.h" 36 36 #include "core/XMLPort.h" 37 #include "core/module/PluginReference.h" 37 38 38 39 #include "infos/PlayerInfo.h" … … 65 66 if (this->xmlfile_) 66 67 Loader::getInstance().unload(this->xmlfile_); 68 69 this->unloadPlugins(); 67 70 } 68 71 } … … 72 75 SUPER(Level, XMLPort, xmlelement, mode); 73 76 77 XMLPortParam(Level, "plugins", setPluginsString, getPluginsString, xmlelement, mode); 74 78 XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype"); 75 79 … … 106 110 Template::getTemplate(*it)->applyOn(this); 107 111 } 112 } 113 114 void Level::setPluginsString(const std::string& pluginsString) 115 { 116 // unload old plugins 117 this->unloadPlugins(); 118 119 // load new plugins 120 this->pluginsString_ = pluginsString; 121 SubString tokens(pluginsString, ","); 122 for (size_t i = 0; i < tokens.size(); ++i) 123 this->plugins_.push_back(new PluginReference(tokens[i])); 124 } 125 126 void Level::unloadPlugins() 127 { 128 // use destroyLater() - this ensures that plugins are not unloaded too early. 129 // Note: When a level gets unloaded, the Level object is usually the last object that gets destroyed. This is because all other 130 // objects inside a level have a StrongPtr (in BaseObject) that references the Level object. This means that the Level 131 // object is only destroyed, when all StrongPtrs that pointed to it were destroyed. But at the time when the last StrongPtr 132 // is destroyed, the other object is not yet fully destroyed because the StrongPtr is destroyed in ~BaseObject (and this 133 // means that e.g. ~Identifiable was not yet called for this object). This means that technically there are still other 134 // objects alive when ~Level is called. This is the reason why we cannot directly destroy() the Plugins - instead we need 135 // to call destroyLater() to ensure that no instances from this plugin exist anymore. 136 for (std::list<PluginReference*>::iterator it = this->plugins_.begin(); it != this->plugins_.end(); ++it) 137 (*it)->destroyLater(); 138 this->plugins_.clear(); 108 139 } 109 140 -
code/branches/core7/src/orxonox/Level.h
r9667 r10580 65 65 // MeshLodInformation* getLodInfo(unsigned int index) const; 66 66 67 void setPluginsString(const std::string& pluginsString); 68 inline const std::string& getPluginsString() const 69 { return this->pluginsString_; } 70 71 void unloadPlugins(); 72 67 73 void setGametypeString(const std::string& gametype); 68 74 inline const std::string& getGametypeString() const … … 70 76 71 77 void networkcallback_applyXMLFile(); 78 79 std::string pluginsString_; 80 std::list<PluginReference*> plugins_; 72 81 73 82 std::string gametype_;
Note: See TracChangeset
for help on using the changeset viewer.