Fix creature memory leaks
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2019-10-06 14:06:17 +02:00
parent 2500c6d996
commit 2966ba268f
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 9 additions and 0 deletions

View File

@ -23,6 +23,12 @@ namespace CreatureLib::Library {
CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant,
float genderRatio, std::string growthRate, uint8_t captureRate, uint8_t baseHappiness); float genderRatio, std::string growthRate, uint8_t captureRate, uint8_t baseHappiness);
~CreatureSpecies(){
for (auto v: _variants)
delete v.second;
_variants.clear();
}
[[nodiscard]] const SpeciesVariant* GetVariant(const std::string& key) const; [[nodiscard]] const SpeciesVariant* GetVariant(const std::string& key) const;
[[nodiscard]] Gender GetRandomGender(Core::Random& rand) const; [[nodiscard]] Gender GetRandomGender(Core::Random& rand) const;
}; };

View File

@ -27,6 +27,7 @@ namespace CreatureLib::Library {
SpeciesVariant(std::string name, float height, float weight, uint32_t baseExperience, SpeciesVariant(std::string name, float height, float weight, uint32_t baseExperience,
std::vector<std::string> types, Core::StatisticSet baseStats, std::vector<std::string> talents, std::vector<std::string> types, Core::StatisticSet baseStats, std::vector<std::string> talents,
std::vector<std::string> secretTalents); std::vector<std::string> secretTalents);
[[nodiscard]] size_t GetTypeCount() const; [[nodiscard]] size_t GetTypeCount() const;
[[nodiscard]] std::string GetType(size_t index) const; [[nodiscard]] std::string GetType(size_t index) const;
[[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const; [[nodiscard]] uint32_t GetStatistic(Core::Statistic stat) const;

View File

@ -13,6 +13,8 @@ namespace CreatureLib::Library {
SpeciesLibrary() = default; SpeciesLibrary() = default;
~SpeciesLibrary(){ ~SpeciesLibrary(){
for (auto s: _species)
delete s.second;
_species.clear(); _species.clear();
} }