diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2011-11-24 05:59:54 +0800 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-11-24 21:13:50 +0300 |
commit | 356807a4c1183304be11f0269cf6d61e2e5dba75 (patch) | |
tree | c7b2ed6881f30dae61ac0f5a17fae87f248953c3 /src/resources/spritedef.cpp | |
parent | c52f9d67cb1be0362e490eb1ff23e7bbf3c4a5a7 (diff) | |
download | manaplus-356807a4c1183304be11f0269cf6d61e2e5dba75.tar.gz manaplus-356807a4c1183304be11f0269cf6d61e2e5dba75.tar.bz2 manaplus-356807a4c1183304be11f0269cf6d61e2e5dba75.tar.xz manaplus-356807a4c1183304be11f0269cf6d61e2e5dba75.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.
Conflicts:
src/resources/spritedef.cpp
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 6b856c5d3..082e528e7 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -39,6 +39,7 @@ #include "debug.h" +std::set<std::string> processedFiles; SpriteReference *SpriteReference::Empty = nullptr; Action *SpriteDef::getAction(std::string action, unsigned num) const @@ -85,6 +86,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(); @@ -350,14 +354,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")) |