Mercurial > sumwars
changeset 2704:613735ae7bdf
refs #105: Fixes coverity issues 1197035, 1197033
author | Augustin Preda |
---|---|
date | Thu, 10 Apr 2014 20:49:24 +0300 |
parents | 7fc84572b43c |
children | 0827b4a67e0b |
files | src/gui/contenteditor/itemeditor.cpp src/gui/contenteditor/monstereditor.cpp |
diffstat | 2 files changed, 54 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gui/contenteditor/itemeditor.cpp Thu Apr 10 20:40:16 2014 +0300 +++ b/src/gui/contenteditor/itemeditor.cpp Thu Apr 10 20:49:24 2014 +0300 @@ -318,15 +318,14 @@ { // Only use item_root if it was not deleted. item_root->SetAttribute("subtype", "EditorItem"); - } + TiXmlElement * item_image = new TiXmlElement("Image"); + item_image->SetAttribute("image", "noMedia.png"); // previously: "set:noMedia.png image:full_image" + item_root->LinkEndChild(item_image); - TiXmlElement * item_image = new TiXmlElement("Image"); - item_image->SetAttribute("image", "noMedia.png"); // previously: "set:noMedia.png image:full_image" - item_root->LinkEndChild(item_image); - - TiXmlElement * item_ri = new TiXmlElement("RenderInfo"); - item_ri->SetAttribute("name", "EditorRenderInfo"); - item_root->LinkEndChild(item_ri); + TiXmlElement * item_ri = new TiXmlElement("RenderInfo"); + item_ri->SetAttribute("name", "EditorRenderInfo"); + item_root->LinkEndChild(item_ri); + } // init the data m_edited_item.m_subtype = "EditorItem";
--- a/src/gui/contenteditor/monstereditor.cpp Thu Apr 10 20:40:16 2014 +0300 +++ b/src/gui/contenteditor/monstereditor.cpp Thu Apr 10 20:49:24 2014 +0300 @@ -74,13 +74,19 @@ copyfoButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&MonsterEditor::onCopyData, this)); // init the internal data + TiXmlNode* linkedNode = NULL; TiXmlElement * monster_root = new TiXmlElement("Monster"); - m_monster_xml.LinkEndChild( monster_root ); - monster_root->SetAttribute("subtype","EditorMonster"); + linkedNode = m_monster_xml.LinkEndChild(monster_root); + + if (linkedNode != NULL) + { + // Only use monster_root if it was not deleted. + monster_root->SetAttribute("subtype", "EditorMonster"); - TiXmlElement * monster_ri = new TiXmlElement("RenderInfo"); - monster_ri->SetAttribute("name","EditorRenderInfo"); - monster_root->LinkEndChild(monster_ri); + TiXmlElement * monster_ri = new TiXmlElement("RenderInfo"); + monster_ri->SetAttribute("name", "EditorRenderInfo"); + monster_root->LinkEndChild(monster_ri); + } m_update_base_content = true; } @@ -179,7 +185,9 @@ bool MonsterEditor::onMonsterModified(const CEGUI::EventArgs& evt) { if (m_no_cegui_events) + { return true; + } CEGUI::WindowManager& win_mgr = CEGUI::WindowManager::getSingleton(); @@ -231,7 +239,7 @@ m_monster_xml.LinkEndChild(ri_temp_xml.RootElement()->Clone()); // parse the XML to the monster data - ObjectLoader::loadMonster(m_monster_xml.FirstChildElement(),true); + ObjectLoader::loadMonster(m_monster_xml.FirstChildElement(), true); // copy to the local Data structure MonsterBasicData* data = ObjectFactory::getMonsterData("EditorMonster"); if (data != 0) @@ -264,17 +272,20 @@ // create a unique renderinfo (to avoid that the object is modified by the editor after creation) RenderInfoEditor* ri_editor = dynamic_cast<RenderInfoEditor*>(ContentEditor::getSingleton().getComponent("RIEditor")); std::string unique_ri = ri_editor->getUniqueRenderinfo(); + // temporarily replace the renderinfo name TiXmlElement * fixed_ri = m_monster_xml.RootElement()->FirstChildElement("RenderInfo"); if (fixed_ri == 0) + { return true; + } std::string name = fixed_ri->Attribute("name"); - fixed_ri->SetAttribute("name",unique_ri.c_str()); + fixed_ri->SetAttribute("name", unique_ri.c_str()); - ObjectLoader::loadMonster(m_monster_xml.FirstChildElement(),true); + ObjectLoader::loadMonster(m_monster_xml.FirstChildElement(), true); - fixed_ri->SetAttribute("name",name.c_str()); + fixed_ri->SetAttribute("name", name.c_str()); Vector pos; float angle; @@ -282,24 +293,29 @@ World* world = World::getWorld(); if (world == 0) + { return true; + } WorldObject* player = world->getLocalPlayer(); if (player == 0) + { return true; + } + Region* region = player->getRegion(); // if the position is set to default, use the player position - pos.m_x = getSpinnerValue("Root/ObjectInfoTabControl/__auto_TabPane__/MonsterTab/MonsterTabControl/__auto_TabPane__/Create/PosXSpinner",0); - pos.m_y = getSpinnerValue("Root/ObjectInfoTabControl/__auto_TabPane__/MonsterTab/MonsterTabControl/__auto_TabPane__/Create/PosYSpinner",0); - angle = getSpinnerValue("Root/ObjectInfoTabControl/__auto_TabPane__/MonsterTab/MonsterTabControl/__auto_TabPane__/Create/AngleSpinner",0); + pos.m_x = getSpinnerValue("Root/ObjectInfoTabControl/__auto_TabPane__/MonsterTab/MonsterTabControl/__auto_TabPane__/Create/PosXSpinner", 0); + pos.m_y = getSpinnerValue("Root/ObjectInfoTabControl/__auto_TabPane__/MonsterTab/MonsterTabControl/__auto_TabPane__/Create/PosYSpinner", 0); + angle = getSpinnerValue("Root/ObjectInfoTabControl/__auto_TabPane__/MonsterTab/MonsterTabControl/__auto_TabPane__/Create/AngleSpinner", 0); if (pos.m_x == 0 && pos.m_y == 0) { pos = player->getShape()->m_center; } // create the object - int id = region->createObject("EditorMonster", pos,angle, height,WorldObject::STATE_ACTIVE); + int id = region->createObject("EditorMonster", pos,angle, height, WorldObject::STATE_ACTIVE); m_created_objects.push_back(std::make_pair(region->getId(), id)); return false; @@ -307,13 +323,19 @@ bool MonsterEditor::onCopyData(const CEGUI::EventArgs& evt) { - std::string objname = getComboboxSelection("Root/ObjectInfoTabControl/__auto_TabPane__/MonsterTab/MonsterTabControl/__auto_TabPane__/Properties/CopyDataBox", ""); + std::string objname = getComboboxSelection( + "Root/ObjectInfoTabControl/__auto_TabPane__/MonsterTab/MonsterTabControl/__auto_TabPane__/Properties/CopyDataBox", ""); + if (objname == "") + { return true; + } MonsterBasicData* modata = ObjectFactory::getMonsterData(objname); if (modata == 0) + { return true; + } m_edited_monster = *modata; @@ -327,11 +349,16 @@ { World* world = World::getWorld(); if (world == 0) + { return true; + } WorldObject* player = world->getLocalPlayer(); if (player == 0) + { return true; + } + //Region* region = player->getRegion(); Vector pos = player->getShape()->m_center; @@ -346,17 +373,22 @@ { World* world = World::getWorld(); if (world == 0) + { return true; + } - std::list< std::pair<int,int> >::iterator it; + std::list< std::pair<int, int> >::iterator it; for (it = m_created_objects.begin(); it != m_created_objects.end(); ++it) { Region* region = world->getRegion(it->first); if (region == 0) + { continue; + } region->deleteObject(it->second); } + m_created_objects.clear(); return true;