From 29ad6702ab90fc75fe9d0422609609fd15123fc3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 26 Sep 2012 01:57:54 +0300 Subject: Some error fixes in atlases. Check if image already in cache and check for mapinfo before using it. --- src/normalopenglgraphics.cpp | 2 +- src/resources/atlasmanager.cpp | 8 ++++++++ src/resources/mapdb.cpp | 6 +++++- src/resources/mapreader.cpp | 7 +++++-- src/resources/resourcemanager.cpp | 6 ++++++ src/resources/resourcemanager.h | 3 +++ 6 files changed, 28 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/normalopenglgraphics.cpp b/src/normalopenglgraphics.cpp index 86cc70cea..4f3fd2aa2 100644 --- a/src/normalopenglgraphics.cpp +++ b/src/normalopenglgraphics.cpp @@ -1358,7 +1358,7 @@ void NormalOpenGLGraphics::debugBindTexture(const Image *image) const std::string texture = image->getIdPath(); if (mOldTexture != texture) { - if (!mOldTexture.empty() && !texture.empty() + if ((!mOldTexture.empty() || !texture.empty()) && mOldTextureId != image->mGLImage) { logger->log("bind: %s (%d) to %s (%d)", mOldTexture.c_str(), 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 &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 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); } -- cgit v1.2.3-60-g2f50