瀏覽代碼

Free memory at TerrainTypeHandler destruction

Tomasz Zieliński 3 年之前
父節點
當前提交
64fd896978
共有 2 個文件被更改,包括 17 次插入0 次删除
  1. 16 0
      lib/Terrain.cpp
  2. 1 0
      lib/Terrain.h

+ 16 - 0
lib/Terrain.cpp

@@ -29,6 +29,22 @@ TerrainTypeHandler::TerrainTypeHandler()
 	initTerrains(allConfigs); //maps will be populated inside
 }
 
+TerrainTypeHandler::~TerrainTypeHandler()
+{
+	for (const auto * terrain : objects)
+	{
+		delete terrain;
+	}
+	for (const auto * river : riverTypes)
+	{
+		delete river;
+	}
+	for (const auto * road : roadTypes)
+	{
+		delete road;
+	}
+}
+
 void TerrainTypeHandler::initTerrains(const std::vector<std::string> & allConfigs)
 {
 	std::vector<std::function<void()>> resolveLater;

+ 1 - 0
lib/Terrain.h

@@ -133,6 +133,7 @@ class DLL_LINKAGE TerrainTypeHandler //TODO: public IHandlerBase ?
 public:
 
 	TerrainTypeHandler();
+	~TerrainTypeHandler();
 
 	const std::vector<TerrainType *> & terrains() const;
 	const TerrainType * getInfoByName(const std::string & terrainName) const;