From 95514a8b6c14ddc86d9b2dfe87d21534b949493d Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 23 Mar 2015 18:37:20 +0300 Subject: Fix memory leak in map animations. --- src/resources/map/map.cpp | 11 +++++++++++ src/resources/map/map.h | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src/resources/map') diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp index 84f1d1049..18e3dc7f5 100644 --- a/src/resources/map/map.cpp +++ b/src/resources/map/map.cpp @@ -1487,3 +1487,14 @@ void Map::setMusicFile(const std::string &file) { setProperty("music", file); } + +void Map::addAnimation(const int gid, TileAnimation *const animation) +{ + std::map::iterator it = mTileAnimations.find(gid); + if (it != mTileAnimations.end()) + { + logger->log("duplicate map animation with gid = %d", gid); + delete (*it).second; + } + mTileAnimations[gid] = animation; +} diff --git a/src/resources/map/map.h b/src/resources/map/map.h index ade7de0be..e33a83d6a 100644 --- a/src/resources/map/map.h +++ b/src/resources/map/map.h @@ -214,8 +214,7 @@ class Map final : public Properties, public ConfigListener /** * Adds a tile animation to the map */ - void addAnimation(const int gid, TileAnimation *const animation) - { mTileAnimations[gid] = animation; } + void addAnimation(const int gid, TileAnimation *const animation); void setDrawLayersFlags(const MapType::MapType &n) { mDrawLayersFlags = n; } -- cgit v1.2.3-60-g2f50