summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-03-16 14:28:45 +0200
committerAndrei Karas <akaras@inbox.ru>2011-03-16 14:28:45 +0200
commit59dc0bffc0f754de8daed29bce3a48e90ea6b4fb (patch)
tree7cd423679a60e25b29318d7a87f367729f8d5fdf /src/resources
parentfbf665912933d10d9132b17802949149d9094fdd (diff)
downloadmv-59dc0bffc0f754de8daed29bce3a48e90ea6b4fb.tar.gz
mv-59dc0bffc0f754de8daed29bce3a48e90ea6b4fb.tar.bz2
mv-59dc0bffc0f754de8daed29bce3a48e90ea6b4fb.tar.xz
mv-59dc0bffc0f754de8daed29bce3a48e90ea6b4fb.zip
Add checks and fix some code style.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/beinginfo.cpp4
-rw-r--r--src/resources/beinginfo.h3
-rw-r--r--src/resources/colordb.cpp1
-rw-r--r--src/resources/dye.cpp5
-rw-r--r--src/resources/emotedb.cpp19
-rw-r--r--src/resources/imageloader.cpp1
-rw-r--r--src/resources/imageset.cpp2
-rw-r--r--src/resources/imagewriter.cpp3
-rw-r--r--src/resources/iteminfo.cpp4
-rw-r--r--src/resources/mapdb.cpp1
-rw-r--r--src/resources/mapreader.cpp9
-rw-r--r--src/resources/monsterdb.cpp3
-rw-r--r--src/resources/npcdb.cpp3
-rw-r--r--src/resources/resource.cpp1
-rw-r--r--src/resources/resourcemanager.cpp5
-rw-r--r--src/resources/soundeffect.h3
-rw-r--r--src/resources/spritedef.cpp3
-rw-r--r--src/resources/spritedef.h5
18 files changed, 53 insertions, 22 deletions
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index ff7428581..d0535ef04 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -92,8 +92,8 @@ const std::string &BeingInfo::getSound(SoundEvent event) const
static std::string empty("");
SoundEvents::const_iterator i = mSounds.find(event);
- return (i == mSounds.end()) ? empty :
- i->second->at(rand() % i->second->size());
+ return (i == mSounds.end() || !i->second) ? empty :
+ i->second->at(rand() % i->second->size());
}
const Attack *BeingInfo::getAttack(int type) const
diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h
index dea8533c9..d5c0c6b28 100644
--- a/src/resources/beinginfo.h
+++ b/src/resources/beinginfo.h
@@ -75,7 +75,8 @@ class BeingInfo
~BeingInfo();
- void setName(const std::string &name) { mName = name; }
+ void setName(const std::string &name)
+ { mName = name; }
const std::string &getName() const
{ return mName; }
diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp
index dce051403..5706c952c 100644
--- a/src/resources/colordb.cpp
+++ b/src/resources/colordb.cpp
@@ -72,6 +72,7 @@ void ColorDB::loadHair()
return;
}
}
+
for_each_xml_child_node(node, root)
{
if (xmlStrEqual(node->name, BAD_CAST "color"))
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index f9c35c5fc..7d92e12ce 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -118,7 +118,8 @@ void DyePalette::getColor(int intensity, int color[3]) const
}
int last = static_cast<int>(mColors.size());
- if (last == 0) return;
+ if (last == 0)
+ return;
int i = intensity * last / 255;
int t = intensity * last % 255;
@@ -144,7 +145,7 @@ void DyePalette::getColor(int intensity, int color[3]) const
// Get the previous color. First color is implicitly black.
int r1 = 0, g1 = 0, b1 = 0;
- if (i > 0)
+ if (i > 0 && i < last + 1)
{
r1 = mColors[i - 1].value[0];
g1 = mColors[i - 1].value[1];
diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp
index 5b20742a8..6084f6092 100644
--- a/src/resources/emotedb.cpp
+++ b/src/resources/emotedb.cpp
@@ -76,6 +76,9 @@ void EmoteDB::load()
for_each_xml_child_node(spriteNode, emoteNode)
{
+ if (!spriteNode->xmlChildrenNode)
+ continue;
+
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
EmoteSprite *currentSprite = new EmoteSprite;
@@ -128,6 +131,9 @@ void EmoteDB::load()
for_each_xml_child_node(spriteNode, emoteNode)
{
+ if (!spriteNode->xmlChildrenNode)
+ continue;
+
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
EmoteSprite *currentSprite = new EmoteSprite;
@@ -160,13 +166,16 @@ void EmoteDB::unload()
i != mEmoteInfos.end();
++i)
{
- while (!i->second->sprites.empty())
+ if (i->second)
{
- delete i->second->sprites.front()->sprite;
- delete i->second->sprites.front();
- i->second->sprites.pop_front();
+ while (!i->second->sprites.empty())
+ {
+ delete i->second->sprites.front()->sprite;
+ delete i->second->sprites.front();
+ i->second->sprites.pop_front();
+ }
+ delete i->second;
}
- delete i->second;
}
mEmoteInfos.clear();
diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp
index 0446e9047..d0c82c09f 100644
--- a/src/resources/imageloader.cpp
+++ b/src/resources/imageloader.cpp
@@ -63,7 +63,6 @@ int ProxyImage::getWidth() const
return mImage->getWidth();
else
return 0;
-// return mSDLImage ? mSDLImage->w : mImage->getWidth();
}
int ProxyImage::getHeight() const
diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp
index d1fceea69..33a66cd11 100644
--- a/src/resources/imageset.cpp
+++ b/src/resources/imageset.cpp
@@ -53,7 +53,7 @@ ImageSet::~ImageSet()
Image* ImageSet::get(size_type i) const
{
- if (i >= mImages.size())
+ if (i >= mImages.size() || i < 0)
{
logger->log("Warning: No sprite %d in this image set", (int) i);
return NULL;
diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp
index 5cc8b4d45..bc5fb7905 100644
--- a/src/resources/imagewriter.cpp
+++ b/src/resources/imagewriter.cpp
@@ -30,6 +30,9 @@
bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename)
{
+ if (!surface)
+ return false;
+
// TODO Maybe someone can make this look nice?
png_structp png_ptr;
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
index 667037c58..70f183d0e 100644
--- a/src/resources/iteminfo.cpp
+++ b/src/resources/iteminfo.cpp
@@ -66,7 +66,9 @@ const std::string &ItemInfo::getSound(EquipmentSoundEvent event) const
i = mSounds.find(event);
- return i == mSounds.end() ? empty : i->second[rand() % i->second.size()];
+ if (i == mSounds.end())
+ return empty;
+ return i->second.size() > 0 ? i->second[rand() % i->second.size()] : empty;
}
std::map<int, int> &ItemInfo::addReplaceSprite(int sprite)
diff --git a/src/resources/mapdb.cpp b/src/resources/mapdb.cpp
index 37b127c02..4050a5072 100644
--- a/src/resources/mapdb.cpp
+++ b/src/resources/mapdb.cpp
@@ -80,7 +80,6 @@ void MapDB::unload()
std::string MapDB::getMapName(std::string name)
{
MapIterator it = mMaps.find(name);
- logger->log("map: " + name);
if (it != mMaps.end())
return it->second;
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index d3cd22988..7bcb08a0f 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -246,6 +246,9 @@ Map *MapReader::readMap(const std::string &filename,
Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
{
+ if (!node)
+ return 0;
+
// Take the filename off the path
const std::string pathDir = path.substr(0, path.rfind("/") + 1);
@@ -274,9 +277,7 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
{
Tileset *tileset = readTileset(childNode, pathDir, map);
if (tileset)
- {
map->addTileset(tileset);
- }
}
else if (xmlStrEqual(childNode->name, BAD_CAST "layer"))
{
@@ -368,7 +369,7 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
void MapReader::readProperties(xmlNodePtr node, Properties *props)
{
- if (!props)
+ if (!node || !props)
return;
for_each_xml_child_node(childNode, node)
@@ -620,6 +621,8 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path,
doc = new XML::Document(filename);
node = doc->rootNode();
+ if (!node)
+ return 0;
// Reset path to be realtive to the tsx file
pathDir = filename.substr(0, filename.rfind("/") + 1);
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index 6ebbaedde..854450bfd 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -98,6 +98,9 @@ void MonsterDB::load()
//iterate <sprite>s and <sound>s
for_each_xml_child_node(spriteNode, monsterNode)
{
+ if (!spriteNode->xmlChildrenNode)
+ continue;
+
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
SpriteReference *currentSprite = new SpriteReference;
diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp
index f20654829..5a1ad9985 100644
--- a/src/resources/npcdb.cpp
+++ b/src/resources/npcdb.cpp
@@ -79,6 +79,9 @@ void NPCDB::load()
SpriteDisplay display;
for_each_xml_child_node(spriteNode, npcNode)
{
+ if (!spriteNode->xmlChildrenNode)
+ continue;
+
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
SpriteReference *currentSprite = new SpriteReference;
diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp
index fb8da6ed2..550a2ea32 100644
--- a/src/resources/resource.cpp
+++ b/src/resources/resource.cpp
@@ -45,7 +45,6 @@ void Resource::decRef()
{
logger->log("Warning: mRefCount already zero for %s", mIdPath.c_str());
return;
-// assert(false);
}
mRefCount--;
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 312c972f9..3ba99d248 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -372,6 +372,8 @@ struct ResourceLoader
ResourceManager::loader fun;
static Resource *load(void *v)
{
+ if (!v)
+ return NULL;
ResourceLoader *l = static_cast< ResourceLoader * >(v);
int fileSize;
if (!l->manager)
@@ -527,7 +529,8 @@ void ResourceManager::release(Resource *res)
time_t timestamp = tv.tv_sec;
res->mTimeStamp = timestamp;
- if (mOrphanedResources.empty()) mOldestOrphan = timestamp;
+ if (mOrphanedResources.empty())
+ mOldestOrphan = timestamp;
mOrphanedResources.insert(*resIter);
mResources.erase(resIter);
diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h
index f9fa0796f..6e208479d 100644
--- a/src/resources/soundeffect.h
+++ b/src/resources/soundeffect.h
@@ -68,7 +68,8 @@ class SoundEffect : public Resource
/**
* Constructor.
*/
- SoundEffect(Mix_Chunk *soundEffect): mChunk(soundEffect) {}
+ SoundEffect(Mix_Chunk *soundEffect): mChunk(soundEffect)
+ { }
Mix_Chunk *mChunk;
};
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index 17ee32fb3..8c13c595c 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -319,7 +319,8 @@ SpriteDef::~SpriteDef()
for (ImageSetIterator i = mImageSets.begin();
i != mImageSets.end(); ++i)
{
- i->second->decRef();
+ if (i->second)
+ i->second->decRef();
}
}
diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h
index 5889bdd94..1ad74d744 100644
--- a/src/resources/spritedef.h
+++ b/src/resources/spritedef.h
@@ -43,7 +43,10 @@ struct SpriteReference
{}
SpriteReference(std::string sprite, int variant)
- { this->sprite = sprite; this->variant = variant; }
+ {
+ this->sprite = sprite;
+ this->variant = variant;
+ }
std::string sprite;
int variant;