ASYLUM: Fix memory leak in ResourceManager

The ResourceManager was never deleting the file data buffers, only removing the entries from the cache.
Thanks to digitall for the patch.
This commit is contained in:
Littleboy 2011-08-06 03:41:02 -04:00 committed by Eugene Sandulenko
parent 734afc0bbc
commit d19ec57732
No known key found for this signature in database
GPG key ID: 014D387312D34F08
2 changed files with 14 additions and 3 deletions

View file

@ -31,6 +31,13 @@ namespace Asylum {
ResourceManager::ResourceManager() : _cdNumber(-1), _musicPackId(kResourcePackInvalid) {
}
ResourceManager::~ResourceManager() {
for (ResourceCache::const_iterator it = _resources.begin(); it != _resources.end(); it++)
delete it->_value;
for (ResourceCache::const_iterator it = _music.begin(); it != _music.end(); it++)
delete it->_value;
}
ResourceEntry *ResourceManager::get(ResourceId id) {
ResourcePackId packId = RESOURCE_PACK(id);
uint16 index = RESOURCE_INDEX(id);
@ -68,11 +75,15 @@ ResourceEntry *ResourceManager::get(ResourceId id) {
}
void ResourceManager::unload(ResourcePackId id) {
if (_resources.contains(id))
if (_resources.contains(id)) {
delete _resources.getVal(id);
_resources.erase(id);
}
if (_music.contains(id))
if (_music.contains(id)) {
delete _music.getVal(id);
_music.erase(id);
}
}
//////////////////////////////////////////////////////////////////////////