From 807ff4b0d06ddd1b6c585446994010d136af2a3d Mon Sep 17 00:00:00 2001 From: Benedikt Galbavy Date: Tue, 30 Jan 2024 14:19:51 +0100 Subject: [PATCH] Fixed a memory leak --- include/SpriteComponent.h | 3 ++- src/SpriteComponent.cpp | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/SpriteComponent.h b/include/SpriteComponent.h index a11865f..ef6786f 100644 --- a/include/SpriteComponent.h +++ b/include/SpriteComponent.h @@ -2,6 +2,7 @@ #include #include +#include #include "AnimationHandler.h" #include "Component.h" @@ -14,7 +15,7 @@ class SpriteComponent : public Component public: int animationIndex = 0; - std::map animations; + std::map> animations; private: TransformComponent* transform; diff --git a/src/SpriteComponent.cpp b/src/SpriteComponent.cpp index 58e2295..6673843 100644 --- a/src/SpriteComponent.cpp +++ b/src/SpriteComponent.cpp @@ -1,7 +1,9 @@ #include "SpriteComponent.h" #include +#include +#include "AnimationHandler.h" #include "Direction.h" #include "TextureManager.h" #include "Entity.h" @@ -16,11 +18,8 @@ SpriteComponent::SpriteComponent(const char* path, bool isAnimated) { animated = isAnimated; - Animation* idle = new Animation((uint8_t)AnimationType::IDLE, 2, 200); - Animation* walk = new Animation((uint8_t)AnimationType::WALK, 2, 200); - - animations.emplace(IDLE, idle); - animations.emplace(WALK, walk); + animations.emplace(IDLE, std::make_unique((uint8_t)AnimationType::IDLE, 2, 200)); + animations.emplace(WALK, std::make_unique((uint8_t)AnimationType::WALK, 2, 200)); playAnimation(IDLE);