diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2011-11-24 05:59:54 +0800 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2011-11-25 01:23:41 +0800 |
commit | 46b94ce1eaac395fe6559206c803a076ec44f852 (patch) | |
tree | 034f35b485e270678b83d72e553e1495f58e58a8 /src/resources/spritedef.cpp | |
parent | a0973bc302f2972c4c70d973090c4d29ea2f7c6d (diff) | |
download | mana-46b94ce1eaac395fe6559206c803a076ec44f852.tar.gz mana-46b94ce1eaac395fe6559206c803a076ec44f852.tar.bz2 mana-46b94ce1eaac395fe6559206c803a076ec44f852.tar.xz mana-46b94ce1eaac395fe6559206c803a076ec44f852.zip |
Prevented circular include in sprite definitions
When including a file that already is included the client won't try to load it
again and end in an endless loop but stops parsing and logs and warning.
Reviewed-by: bjorn.
Diffstat (limited to 'src/resources/spritedef.cpp')
-rw-r--r-- | src/resources/spritedef.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 4375fb89..e0cbfd1f 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -39,6 +39,7 @@ SpriteReference *SpriteReference::Empty = new SpriteReference( paths.getStringValue("spriteErrorFile"), 0); +std::set<std::string> processedFiles; Action *SpriteDef::getAction(const std::string &action) const { @@ -60,6 +61,9 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant) if (pos != std::string::npos) palettes = animationFile.substr(pos + 1); + processedFiles.clear(); + processedFiles.insert(animationFile); + XML::Document doc(animationFile.substr(0, pos)); xmlNodePtr rootNode = doc.rootNode(); @@ -284,14 +288,21 @@ void SpriteDef::loadAnimation(xmlNodePtr animationNode, void SpriteDef::includeSprite(xmlNodePtr includeNode) { - // TODO: Perform circular dependency check, since it's easy to crash the - // client this way. - const std::string filename = XML::getProperty(includeNode, "file", ""); + std::string filename = XML::getProperty(includeNode, "file", ""); if (filename.empty()) return; + filename = paths.getStringValue("sprites") + filename; + + if (processedFiles.find(filename) != processedFiles.end()) + { + logger->log("Error, Tried to include %s which already is included.", + filename.c_str()); + return; + } + processedFiles.insert(filename); - XML::Document doc(paths.getStringValue("sprites") + filename); + XML::Document doc(filename); xmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "sprite")) |