Mercurial > sumwars
changeset 2702:2d2674a79a21
refs #105: Fixes coverity issue 1197036
author | Augustin Preda |
---|---|
date | Thu, 10 Apr 2014 20:06:52 +0300 |
parents | bf03e143880f |
children | 7fc84572b43c |
files | src/gui/contenteditor/fixedobjecteditor.cpp |
diffstat | 1 files changed, 60 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gui/contenteditor/fixedobjecteditor.cpp Wed Apr 09 23:55:10 2014 +0300 +++ b/src/gui/contenteditor/fixedobjecteditor.cpp Thu Apr 10 20:06:52 2014 +0300 @@ -86,12 +86,19 @@ // init the internal data + TiXmlNode* linkedNode = NULL; TiXmlElement * fixed_root = new TiXmlElement("Object"); - m_fixed_object_xml.LinkEndChild( fixed_root ); - fixed_root->SetAttribute("subtype","EditorFixedObject"); + linkedNode = m_fixed_object_xml.LinkEndChild(fixed_root); + if (fixed_root == NULL) + { + // Failed to link the root item. + return; + } + + fixed_root->SetAttribute("subtype", "EditorFixedObject"); TiXmlElement * fixed_ri = new TiXmlElement("RenderInfo"); - fixed_ri->SetAttribute("name","EditorRenderInfo"); + fixed_ri->SetAttribute("name", "EditorRenderInfo"); fixed_root->LinkEndChild(fixed_ri); m_update_base_content = true; @@ -192,11 +199,17 @@ // set the layer combobox std::string layer = "Normal"; if (m_edited_fixed_object.m_layer == WorldObject::LAYER_BASE) + { layer = "Base"; + } else if (m_edited_fixed_object.m_layer == WorldObject::LAYER_AIR) + { layer = "Air"; + } else if (m_edited_fixed_object.m_layer == WorldObject::LAYER_NOCOLLISION) + { layer == "NoCollision"; + } CEGUI::ListboxItem* selection = layerSelector->findItemWithText(CEGUI::String(layer),0); if (selection != 0) @@ -213,7 +226,9 @@ bool FixedObjectEditor::onFixedObjectModified(const CEGUI::EventArgs& evt) { if (m_no_cegui_events) + { return true; + } CEGUI::WindowManager& win_mgr = CEGUI::WindowManager::getSingleton(); @@ -246,13 +261,21 @@ std::string layer = layerSelector->getText().c_str(); if (layer == "Base") + { m_edited_fixed_object.m_layer = WorldObject::LAYER_BASE; + } else if (layer == "Air") + { m_edited_fixed_object.m_layer = WorldObject::LAYER_AIR; + } else if (layer == "NoCollision") + { m_edited_fixed_object.m_layer = WorldObject::LAYER_NOCOLLISION; + } else + { m_edited_fixed_object.m_layer = WorldObject::LAYER_BASE | WorldObject::LAYER_AIR; + } m_modified_fixed_object = true; @@ -283,10 +306,10 @@ Ogre::SceneNode* topnode = ri_editor->getEditedGraphicObject()->getTopNode(); topnode->_updateBounds(); - Ogre::Vector3 bbox_min(1000,1000,1000); - Ogre::Vector3 bbox_max(-1000,-1000,-1000); + Ogre::Vector3 bbox_min(1000, 1000, 1000); + Ogre::Vector3 bbox_max(-1000, -1000, -1000); - getNodeBounds(topnode,bbox_min,bbox_max); + getNodeBounds(topnode, bbox_min, bbox_max); double size_x = bbox_max[0] - bbox_min[0]; double size_z = bbox_max[2] - bbox_min[2]; @@ -328,7 +351,7 @@ m_fixed_object_xml.LinkEndChild(ri_temp_xml.RootElement()->Clone()); // parse the XML to the fixed object data - ObjectLoader::loadObject(m_fixed_object_xml.FirstChildElement(),true); + ObjectLoader::loadObject(m_fixed_object_xml.FirstChildElement(), true); // copy to the local Data structure FixedObjectData* data = ObjectFactory::getFixedObjectData("EditorFixedObject"); if (data != 0) @@ -345,7 +368,7 @@ int err_row = ri_temp_xml.ErrorRow(); int err_col = ri_temp_xml.ErrorCol(); - setMultiLineEditboxCursor("Root/ObjectInfoTabControl/__auto_TabPane__/FixedObjectTab/FixedObjectTabControl/__auto_TabPane__/XML/FOXMLEditbox",err_row,err_col); + setMultiLineEditboxCursor("Root/ObjectInfoTabControl/__auto_TabPane__/FixedObjectTab/FixedObjectTabControl/__auto_TabPane__/XML/FOXMLEditbox", err_row, err_col); } return true; @@ -361,14 +384,16 @@ // temporarily replace the renderinfo name TiXmlElement * fixed_ri = m_fixed_object_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::loadObject(m_fixed_object_xml.FirstChildElement(),true); + ObjectLoader::loadObject(m_fixed_object_xml.FirstChildElement(), true); - fixed_ri->SetAttribute("name",name.c_str()); + fixed_ri->SetAttribute("name", name.c_str()); Vector pos; float angle; @@ -376,24 +401,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__/FixedObjectTab/FixedObjectTabControl/__auto_TabPane__/Create/PosXSpinner", 0); pos.m_y = getSpinnerValue("Root/ObjectInfoTabControl/__auto_TabPane__/FixedObjectTab/FixedObjectTabControl/__auto_TabPane__/Create/PosYSpinner", 0); - angle = getSpinnerValue("Root/ObjectInfoTabControl/__auto_TabPane__/FixedObjectTab/FixedObjectTabControl/__auto_TabPane__/Create/AngleSpinner",0); + angle = getSpinnerValue("Root/ObjectInfoTabControl/__auto_TabPane__/FixedObjectTab/FixedObjectTabControl/__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("EditorFixedObject", pos,angle, height,WorldObject::STATE_ACTIVE); + int id = region->createObject("EditorFixedObject", pos, angle, height, WorldObject::STATE_ACTIVE); m_created_objects.push_back(std::make_pair(region->getId(), id)); return false; @@ -403,12 +433,16 @@ { std::string objname = getComboboxSelection("Root/ObjectInfoTabControl/__auto_TabPane__/FixedObjectTab/FixedObjectTabControl/__auto_TabPane__/Properties/CopyDataBox", ""); if (objname == "") + { return true; + } FixedObjectData* fodata = ObjectFactory::getFixedObjectData(objname); if (fodata == 0) + { return true; - + } + m_edited_fixed_object = *fodata; m_modified_fixed_object = true; @@ -421,11 +455,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; @@ -440,17 +479,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;