summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-12-03 13:32:07 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-12-03 13:32:07 +0000
commit092bf185fc056338bcde2749a304e576edf342fd (patch)
tree7f5c6424998ba44f8732ec12d07f315297d8e49f /src/resources
parent100d02440e6715b7e02867b84fed759ed4258c73 (diff)
downloadmana-client-092bf185fc056338bcde2749a304e576edf342fd.tar.gz
mana-client-092bf185fc056338bcde2749a304e576edf342fd.tar.bz2
mana-client-092bf185fc056338bcde2749a304e576edf342fd.tar.xz
mana-client-092bf185fc056338bcde2749a304e576edf342fd.zip
Don't try to play empty strings as sounds, and don't return a SoundEffect
instance when Mix_Chunk loading failed.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/resourcemanager.cpp4
-rw-r--r--src/resources/soundeffect.cpp19
2 files changed, 15 insertions, 8 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 9ad18db3..4ed316cf 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -174,9 +174,9 @@ ResourceManager::get(const E_RESOURCE_TYPE &type, const std::string &idPath)
free(buffer);
- if (resource) {
+ if (resource)
+ {
resource->incRef();
-
mResources[idPath] = resource;
}
diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp
index 3340e5ea..bb35218e 100644
--- a/src/resources/soundeffect.cpp
+++ b/src/resources/soundeffect.cpp
@@ -23,6 +23,8 @@
#include "soundeffect.h"
+#include "../log.h"
+
SoundEffect::SoundEffect(const std::string &idPath, Mix_Chunk *soundEffect):
Resource(idPath),
mChunk(soundEffect)
@@ -41,13 +43,18 @@ SoundEffect::load(void *buffer, unsigned int bufferSize,
// Load the raw file data from the buffer in an RWops structure
SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize);
- // Use Mix_LoadWAV_RW to load the raw music data
- Mix_Chunk *tmpSoundEffect = Mix_LoadWAV_RW(rw, 0);
-
- // Now free the SDL_RWops data
- SDL_FreeRW(rw);
+ // Load the music data and free the RWops structure
+ Mix_Chunk *tmpSoundEffect = Mix_LoadWAV_RW(rw, 1);
- return new SoundEffect(idPath, tmpSoundEffect);
+ if (tmpSoundEffect)
+ {
+ return new SoundEffect(idPath, tmpSoundEffect);
+ }
+ else
+ {
+ logger->log("Error while loading sound effect (%s)", idPath.c_str());
+ return NULL;
+ }
}
bool