mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-15 14:09:06 +00:00
Fix possible crash when saving animation to non-existing file + loading malformed XML from skin file.
Also fix skeletal cache memory leak.
This commit is contained in:
parent
26dc8560b7
commit
15379db4b8
3 changed files with 16 additions and 9 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -34,13 +34,13 @@ std::string SkeletalSprite::secondaryAnimationPath = "";
|
|||
|
||||
static std::map<std::string, XMLDocument*> skelCache;
|
||||
|
||||
static XMLDocument *_retrieveSkeletalXML(const std::string& name)
|
||||
static XMLDocument *_retrieveSkeletalXML(const std::string& name, bool keepEmpty)
|
||||
{
|
||||
std::map<std::string, XMLDocument*>::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<std::string, XMLDocument*>::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 = "";
|
||||
|
|
Loading…
Reference in a new issue