diff --git a/BBGE/Base.cpp b/BBGE/Base.cpp index 7cc5958..785e3fb 100644 --- a/BBGE/Base.cpp +++ b/BBGE/Base.cpp @@ -547,13 +547,13 @@ tinyxml2::XMLError readXML(const std::string& fn, tinyxml2::XMLDocument& doc) return err; } -tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr /* = 0 */) +tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr /* = 0 */, bool keepEmpty /* = false */) { tinyxml2::XMLDocument *doc = new tinyxml2::XMLDocument(); tinyxml2::XMLError err = readXML(fn, *doc); if(perr) *perr = err; - if(err != tinyxml2::XML_SUCCESS) + if(err != tinyxml2::XML_SUCCESS && !keepEmpty) { delete doc; doc = NULL; diff --git a/BBGE/Base.h b/BBGE/Base.h index 8471dd4..7e51583 100644 --- a/BBGE/Base.h +++ b/BBGE/Base.h @@ -206,7 +206,7 @@ bool exists(const std::string &f, bool makeFatal = false, bool skipVFS = false); void errorLog(const std::string &s); void debugLog(const std::string &s); char *readFile(const std::string& path, unsigned long *size_ret = 0); -tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr = 0); +tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr = 0, bool keepEmpty = false); tinyxml2::XMLError readXML(const std::string& fn, tinyxml2::XMLDocument& doc); char *readCompressedFile(std::string path, unsigned long *size_ret = 0); void forEachFile(std::string path, std::string type, void callback(const std::string &filename, intptr_t param), intptr_t param); diff --git a/BBGE/SkeletalSprite.cpp b/BBGE/SkeletalSprite.cpp index 85dc918..069cd86 100644 --- a/BBGE/SkeletalSprite.cpp +++ b/BBGE/SkeletalSprite.cpp @@ -34,13 +34,13 @@ std::string SkeletalSprite::secondaryAnimationPath = ""; static std::map skelCache; -static XMLDocument *_retrieveSkeletalXML(const std::string& name) +static XMLDocument *_retrieveSkeletalXML(const std::string& name, bool keepEmpty) { std::map::iterator it = skelCache.find(name); if(it != skelCache.end()) return it->second; - XMLDocument *doc = readXML(name); + XMLDocument *doc = readXML(name, NULL, keepEmpty); if(doc) skelCache[name] = doc; @@ -49,6 +49,8 @@ static XMLDocument *_retrieveSkeletalXML(const std::string& name) void SkeletalSprite::clearCache() { + for(std::map::iterator it = skelCache.begin(); it != skelCache.end(); ++it) + delete it->second; skelCache.clear(); } @@ -869,7 +871,7 @@ bool SkeletalSprite::saveSkeletal(const std::string &fn) } int i = 0; - XMLDocument *xml = _retrieveSkeletalXML(file); + XMLDocument *xml = _retrieveSkeletalXML(file, true); xml->Clear(); XMLElement *animationLayers = xml->NewElement("AnimationLayers"); @@ -1179,10 +1181,15 @@ void SkeletalSprite::loadSkin(const std::string &fn) if (!exists(file)) { - errorLog("Could not load skin[" + file + "]"); + errorLog("Could not load skin[" + file + "] - File not found."); + return; + } + XMLDocument *d = _retrieveSkeletalXML(file, false); + if(!d) + { + errorLog("Could not load skin[" + file + "] - Malformed XML."); return; } - XMLDocument *d = _retrieveSkeletalXML(file); XMLElement *bonesXml = d->FirstChildElement("Bones"); if (bonesXml) @@ -1315,7 +1322,7 @@ void SkeletalSprite::loadSkeletal(const std::string &fn) file = core->adjustFilenameCase(file); - XMLDocument *xml = _retrieveSkeletalXML(file); + XMLDocument *xml = _retrieveSkeletalXML(file, false); if(!xml) { filenameLoaded = "";