0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 07:53:43 +00:00

Fixed a memory leak

This commit is contained in:
Benedikt Galbavy 2024-01-30 14:19:51 +01:00
parent cf02eef8fd
commit 807ff4b0d0
2 changed files with 6 additions and 6 deletions

View File

@ -2,6 +2,7 @@
#include <map>
#include <SDL_render.h>
#include <memory>
#include "AnimationHandler.h"
#include "Component.h"
@ -14,7 +15,7 @@ class SpriteComponent : public Component
public:
int animationIndex = 0;
std::map<AnimationType, Animation*> animations;
std::map<AnimationType, std::unique_ptr<Animation>> animations;
private:
TransformComponent* transform;

View File

@ -1,7 +1,9 @@
#include "SpriteComponent.h"
#include <SDL_timer.h>
#include <memory>
#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<Animation>((uint8_t)AnimationType::IDLE, 2, 200));
animations.emplace(WALK, std::make_unique<Animation>((uint8_t)AnimationType::WALK, 2, 200));
playAnimation(IDLE);