summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-09-26 01:57:54 +0300
committerAndrei Karas <akaras@inbox.ru>2012-09-30 02:57:14 +0300
commit29ad6702ab90fc75fe9d0422609609fd15123fc3 (patch)
tree0b9cee6f48b0dd28455e5ef86800efc30f38064d /src/resources
parent660dcd09eb2c156e3ca8bafe0c1a339041204d33 (diff)
downloadmv-29ad6702ab90fc75fe9d0422609609fd15123fc3.tar.gz
mv-29ad6702ab90fc75fe9d0422609609fd15123fc3.tar.bz2
mv-29ad6702ab90fc75fe9d0422609609fd15123fc3.tar.xz
mv-29ad6702ab90fc75fe9d0422609609fd15123fc3.zip
Some error fixes in atlases.
Check if image already in cache and check for mapinfo before using it.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/atlasmanager.cpp8
-rw-r--r--src/resources/mapdb.cpp6
-rw-r--r--src/resources/mapreader.cpp7
-rw-r--r--src/resources/resourcemanager.cpp6
-rw-r--r--src/resources/resourcemanager.h3
5 files changed, 27 insertions, 3 deletions
diff --git a/src/resources/atlasmanager.cpp b/src/resources/atlasmanager.cpp
index 770e43412..401dba0cb 100644
--- a/src/resources/atlasmanager.cpp
+++ b/src/resources/atlasmanager.cpp
@@ -92,10 +92,18 @@ AtlasResource *AtlasManager::loadTextureAtlas(const std::string &name,
void AtlasManager::loadImages(const StringVect &files,
std::vector<Image*> &images)
{
+ const ResourceManager *const resman = ResourceManager::getInstance();
+
for (StringVectCIter it = files.begin(), it_end = files.end();
it != it_end; ++ it)
{
const std::string str = *it;
+ if (resman->isInCache(str))
+ {
+ logger->log("Resource %s already in cache", str.c_str());
+ continue;
+ }
+
SDL_RWops *rw = PHYSFSRWOPS_openRead(str.c_str());
Image *image = sdlImageHelper->load(rw);
if (image)
diff --git a/src/resources/mapdb.cpp b/src/resources/mapdb.cpp
index 2b2beed89..84b5f6cf3 100644
--- a/src/resources/mapdb.cpp
+++ b/src/resources/mapdb.cpp
@@ -121,8 +121,12 @@ void MapDB::readAtlas(XmlNodePtr node)
void MapDB::loadInfo()
{
XML::Document *doc = new XML::Document("maps.xml");
-
const XmlNodePtr root = doc->rootNode();
+ if (!root)
+ {
+ delete doc;
+ return;
+ }
for_each_xml_child_node(node, root)
{
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index f81741227..ede630d0c 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -279,8 +279,11 @@ Map *MapReader::readMap(XmlNodePtr node, const std::string &path)
if (graphicsManager.getUseAtlases())
{
const MapDB::MapInfo *const info = MapDB::getMapAtlas(fileName);
- map->setAtlas(ResourceManager::getInstance()->getAtlas(
- info->atlas, *info->files));
+ if (info)
+ {
+ map->setAtlas(ResourceManager::getInstance()->getAtlas(
+ info->atlas, *info->files));
+ }
}
#endif
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 5270e6f60..9beba49e7 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -399,6 +399,12 @@ Resource *ResourceManager::getFromCache(const std::string &filename,
return getFromCache(ss.str());
}
+bool ResourceManager::isInCache(const std::string &idPath) const
+{
+ const ResourceCIterator &resIter = mResources.find(idPath);
+ return (resIter != mResources.end() && resIter->second);
+}
+
Resource *ResourceManager::getFromCache(const std::string &idPath)
{
// Check if the id exists, and return the value if it does.
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 551b00a33..6c089a243 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -285,6 +285,7 @@ class ResourceManager final
typedef std::map<std::string, Resource*> Resources;
typedef Resources::iterator ResourceIterator;
+ typedef Resources::const_iterator ResourceCIterator;
#ifdef DEBUG_DUMP_LEAKS
Resources* getResources()
@@ -296,6 +297,8 @@ class ResourceManager final
bool cleanOrphans(const bool always = false);
+ bool isInCache(const std::string &idPath) const;
+
static void addDelayedAnimation(AnimationDelayLoad *const animation)
{ mDelayedAnimations.push_back(animation); }