Remove All Memory leaks

This commit is contained in:
Bram Verhulst
2024-05-02 14:57:47 +02:00
parent b6be73019f
commit 77784a167e
8 changed files with 56 additions and 102 deletions

View File

@@ -5,7 +5,9 @@
#include <algorithm>
#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();
}

View File

@@ -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";

View File

@@ -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);

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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;
}