From 9937b98cdaa2bfae6005f2abf7a5bf0127649a46 Mon Sep 17 00:00:00 2001
From: Joakim Hunskaar <joakim.borge.hunskar@gmail.com>
Date: Thu, 2 May 2024 20:20:34 +0200
Subject: [PATCH] Image now deletes its texture

---
 dependencies/subprojects/animationwindow/include/Image.h | 1 +
 dependencies/subprojects/animationwindow/src/Image.cpp   | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/dependencies/subprojects/animationwindow/include/Image.h b/dependencies/subprojects/animationwindow/include/Image.h
index f9af259..a249f2b 100644
--- a/dependencies/subprojects/animationwindow/include/Image.h
+++ b/dependencies/subprojects/animationwindow/include/Image.h
@@ -13,6 +13,7 @@ namespace TDT4102 {
     public:
         explicit Image();
         explicit Image(std::filesystem::path pathToImageFile);
+        ~Image();
 
         int width = 0;
         int height = 0;
diff --git a/dependencies/subprojects/animationwindow/src/Image.cpp b/dependencies/subprojects/animationwindow/src/Image.cpp
index 42c1987..8655f9d 100644
--- a/dependencies/subprojects/animationwindow/src/Image.cpp
+++ b/dependencies/subprojects/animationwindow/src/Image.cpp
@@ -34,3 +34,10 @@ void TDT4102::Image::draw(SDL_Renderer *renderer, TDT4102::Point location, int i
 
     SDL_RenderCopy(renderer, texture, nullptr, &imageBounds);
 }
+
+TDT4102::Image::~Image() {
+    if (texture != nullptr) {
+        SDL_DestroyTexture(texture);
+        texture = nullptr;
+    }
+}
-- 
GitLab