diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index eb02e56..06cbab8 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -4247,7 +4247,7 @@ bool Game::loadSceneXML(std::string scene) l->position = Vector(atoi(lensFlare->Attribute("x")),atoi(lensFlare->Attribute("y"))); addRenderObject(l, LR_LIGHTING); - XMLElement *lSF = doc.NewElement("LensFlare"); + XMLElement *lSF = saveFile->NewElement("LensFlare"); lSF->SetAttribute("inc", lensFlare->Attribute("inc")); lSF->SetAttribute("x", lensFlare->Attribute("x")); lSF->SetAttribute("y", lensFlare->Attribute("y")); @@ -4262,7 +4262,7 @@ bool Game::loadSceneXML(std::string scene) XMLElement *level = doc.FirstChildElement("Level"); if (level) { - XMLElement *levelSF = doc.NewElement("Level"); + XMLElement *levelSF = saveFile->NewElement("Level"); if (level->Attribute("tileset")) { elementTemplatePack = level->Attribute("tileset"); @@ -4595,7 +4595,7 @@ bool Game::loadSceneXML(std::string scene) XMLElement *quad = doc.FirstChildElement("Quad"); while (quad) { - XMLElement *qSF = doc.NewElement("Quad"); + XMLElement *qSF = saveFile->NewElement("Quad"); int x=0, y=0, z=0; int w=0,h=0; bool cull=true; @@ -4855,7 +4855,7 @@ bool Game::loadSceneXML(std::string scene) schoolFish = schoolFish->NextSiblingElement("SchoolFish"); - XMLElement *newSF = doc.NewElement("SchoolFish"); + XMLElement *newSF = saveFile->NewElement("SchoolFish"); newSF->SetAttribute("x", x); newSF->SetAttribute("y", y); newSF->SetAttribute("id", id); @@ -5308,20 +5308,27 @@ bool Game::saveScene(std::string scene) std::string fn = getSceneFilename(scene); - XMLPrinter printer; - this->saveFile->Print(&printer); - XMLDocument saveFile; - saveFile.Parse(printer.CStr(), printer.CStrSize()); + + // hackish: Deep-clone XML doc + { + XMLPrinter printer; + this->saveFile->Print(&printer); + + XMLError xmlerr = saveFile.Parse(printer.CStr(), printer.CStrSize()); + if(xmlerr != XML_SUCCESS) + { + std::ostringstream os; + os << "Game::saveScene(): Whoops? Deep cloning level XML failed: Error " << xmlerr; + errorLog(os.str()); + } + } XMLElement *level = saveFile.FirstChildElement("Level"); - - XMLElement *levelLocal = saveFile.NewElement("Level"); - bool addIt = false; - if (!level) + if(!level) { - level = levelLocal; - addIt = true; + level = saveFile.NewElement("Level"); + saveFile.InsertFirstChild(level); } if (level) @@ -5348,11 +5355,6 @@ bool Game::saveScene(std::string scene) } } - if (addIt) - { - saveFile.InsertEndChild(levelLocal); - } - /* XMLElement *level = doc.NewElement("Level"); level->SetAttribute("elementTemplatePack", elementTemplatePack); @@ -5500,7 +5502,7 @@ bool Game::saveScene(std::string scene) } */ - bool result = saveFile.SaveFile(fn.c_str()); + bool result = saveFile.SaveFile(fn.c_str()) == XML_SUCCESS; if (result) debugLog("Successfully saved map: " + fn); else diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index c09db3f..3313034 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -1044,7 +1044,7 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn) animations->InsertEndChild(animation); } xml->InsertEndChild(animations); - return xml->SaveFile(file.c_str()); + return xml->SaveFile(file.c_str()) == XML_SUCCESS; } int SkeletalSprite::getBoneIdx(Bone *b)