From 77784a167ea66911752a80db57d72f9104b22467 Mon Sep 17 00:00:00 2001 From: Bram Verhulst Date: Thu, 2 May 2024 14:57:47 +0200 Subject: [PATCH] Remove All Memory leaks --- .idea/.idea.Motherload/.idea/workspace.xml | 128 ++++++--------------- Engine/BaseGame.cpp | 1 - Game/Game.cpp | 3 + Game/GridSystem/WorldTile.cpp | 1 + Game/GroundTileTypeManager.cpp | 15 ++- Game/Levels/World/WorldLevel.cpp | 2 +- Game/Player.cpp | 5 +- Game/main.cpp | 3 - 8 files changed, 56 insertions(+), 102 deletions(-) diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml index 2f7cf3c..98534b4 100644 --- a/.idea/.idea.Motherload/.idea/workspace.xml +++ b/.idea/.idea.Motherload/.idea/workspace.xml @@ -12,19 +12,13 @@ - - - - - - - - + + + - - + @@ -289,6 +227,8 @@ + + diff --git a/Engine/BaseGame.cpp b/Engine/BaseGame.cpp index d257b78..ea85f7a 100644 --- a/Engine/BaseGame.cpp +++ b/Engine/BaseGame.cpp @@ -275,7 +275,6 @@ void BaseGame::CleanupGameEngine() ImGui::DestroyContext(); SDL_FreeSurface(m_pIcon); - delete m_pIcon; SDL_GL_DeleteContext(m_pContext); diff --git a/Game/Game.cpp b/Game/Game.cpp index 70811cf..cc7e302 100644 --- a/Game/Game.cpp +++ b/Game/Game.cpp @@ -5,7 +5,9 @@ #include #include "colors.h" +#include "GroundTileTypeManager.h" #include "utils.h" +#include "GridSystem/WorldTile.h" #include "Levels/World/WorldLevel.h" @@ -30,6 +32,7 @@ void Game::Cleanup() { //TODO: ask how 2 delete the TextureManager ScreenManager::DestroyInstance(); + GroundTileTypeManager::DestroyInstance(); TextureManager::DestroyInstance(); } diff --git a/Game/GridSystem/WorldTile.cpp b/Game/GridSystem/WorldTile.cpp index d6f4fb7..59575e6 100644 --- a/Game/GridSystem/WorldTile.cpp +++ b/Game/GridSystem/WorldTile.cpp @@ -65,6 +65,7 @@ void InitializeGroundTiles() { { GroundTileTypeManager::GetInstance()->IRON, 0.1f }, }; } + WorldTile::WorldTile(const Vector2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager) : m_Position { position }, m_GroundTileType { groundTileType }, m_pGridManager { pGridManager } { // const std::string dirtPath = + "tiles/dirt/dirt" + std::to_string(utils::randRange(1, 5)) + ".png"; diff --git a/Game/GroundTileTypeManager.cpp b/Game/GroundTileTypeManager.cpp index 9b055c8..456a1b9 100644 --- a/Game/GroundTileTypeManager.cpp +++ b/Game/GroundTileTypeManager.cpp @@ -12,8 +12,21 @@ GroundTileTypeManager* GroundTileTypeManager::GetInstance() { return m_pInstance; } void GroundTileTypeManager::DestroyInstance() { + delete m_pInstance->AIR; + delete m_pInstance->DIRT; + delete m_pInstance->STONE; + delete m_pInstance->LAVA; + delete m_pInstance->IRON; + delete m_pInstance->BRONZE; + delete m_pInstance->GOLD; + delete m_pInstance->HARD_LEFT; + delete m_pInstance->HARD_RIGHT; + delete m_pInstance->HARD_MIDDLE; + delete m_pInstance->GRASS; + + delete m_pInstance; } -GroundTileTypeManager::GroundTileTypeManager(): AIR(new GroundTileType("", GroundTileTypes::Air)), DIRT(new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5)){ +GroundTileTypeManager::GroundTileTypeManager() { } // void GroundTileTypeManager::Initialize() { // AIR = new GroundTileType("", GroundTileTypes::Air); diff --git a/Game/Levels/World/WorldLevel.cpp b/Game/Levels/World/WorldLevel.cpp index 0346d61..7144913 100644 --- a/Game/Levels/World/WorldLevel.cpp +++ b/Game/Levels/World/WorldLevel.cpp @@ -69,7 +69,7 @@ WorldLevel::~WorldLevel() { delete m_mineralBuilding; delete m_junkBuilding; delete m_repairBuilding; - //delete m_pTextTexture; + } void WorldLevel::Update(float elapsedSec) { m_fps = 1 / elapsedSec; diff --git a/Game/Player.cpp b/Game/Player.cpp index 259b916..12e2763 100644 --- a/Game/Player.cpp +++ b/Game/Player.cpp @@ -34,8 +34,9 @@ Player::Player(Player&& other) { Player::~Player() { delete m_walkAnimation; - // delete m_turnAnimation; - // delete m_digAnimation; + delete m_turnAnimation; + delete m_digAnimation; + delete m_digStartAnimation; } Collision::CollisionRect Player::GetCollisionRect() const { diff --git a/Game/main.cpp b/Game/main.cpp index ab3bf77..f0089d2 100644 --- a/Game/main.cpp +++ b/Game/main.cpp @@ -12,13 +12,10 @@ int SDL_main(int argv, char** args) { StartHeapControl(); - new Button(); - auto pGame { new Game { Window { "Motherload - Verhulst, Bram - 1DAEGD16E", Viewport.x, Viewport.y, false} } }; pGame->Run(); delete pGame; - //DumpMemoryLeaks(); return 0; }