From 3270c2bcd37d23c68f281fedc60d71106e9926e7 Mon Sep 17 00:00:00 2001 From: aleksav013 Date: Sun, 6 Jun 2021 15:35:16 +0200 Subject: Fixing memory leak --- src/Game.cpp | 8 ++++---- src/State.cpp | 16 +++++++++++++++- src/includes/State.hpp | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index 2fadf1c..c0bad0e 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -75,10 +75,10 @@ void Game::inittex() void Game::initent() { igrac = Player(sf::Vector2f(sirina/2.0,visina/2.0),sf::Vector2f(100.0f,100.0f),sf::Color::White); - for(size_t i=0;i<20;i++) nep1.push_back(Enemy1(sf::Vector2f(Global::rng()%sirina,Global::rng()%visina),sf::Vector2f(50.0f,50.0f),sf::Color::Red)); - for(size_t i=0;i<7;i++) nep2.push_back(Enemy2(sf::Vector2f(Global::rng()%sirina,Global::rng()%visina),sf::Vector2f(50.0f,50.0f),sf::Color::Cyan));//(253,106,2))); - for(size_t i=0;i<4;i++) nep3.push_back(Enemy3(sf::Vector2f(Global::rng()%sirina,Global::rng()%visina),sf::Vector2f(50.0f,50.0f),sf::Color::Yellow)); - pow.push_back(Powerup(sf::Vector2f(Global::rng()%sirina,Global::rng()%visina),sf::Vector2f(50.0f,50.0f),sf::Color::White,Global::rng()%3+1)); + for(size_t i=0;i<20;i++) nep1.emplace_back(sf::Vector2f(Global::rng()%sirina,Global::rng()%visina),sf::Vector2f(50.0f,50.0f),sf::Color::Red); + for(size_t i=0;i<7;i++) nep2.emplace_back(sf::Vector2f(Global::rng()%sirina,Global::rng()%visina),sf::Vector2f(50.0f,50.0f),sf::Color::Cyan); + for(size_t i=0;i<4;i++) nep3.emplace_back(sf::Vector2f(Global::rng()%sirina,Global::rng()%visina),sf::Vector2f(50.0f,50.0f),sf::Color::Yellow); + pow.emplace_back(sf::Vector2f(Global::rng()%sirina,Global::rng()%visina),sf::Vector2f(50.0f,50.0f),sf::Color::White,Global::rng()%3+1); } void Game::updatewin() { diff --git a/src/State.cpp b/src/State.cpp index 8a74331..a404666 100644 --- a/src/State.cpp +++ b/src/State.cpp @@ -121,7 +121,11 @@ void State::loop() { prozor.draw(podloga); prozor.draw(krajtext); - if(newgame) igra=new Game(&prozor,font,tex); + if(newgame) + { + delete igra; + igra=new Game(&prozor,font,tex); + } } if(pause) { @@ -134,4 +138,14 @@ void State::loop() ischanged=0; newgame=0; } + delete igra; +} +State::~State() +{ + delete font["default"]; + delete tex["neprijatelj"]; + delete tex["health"]; + delete tex["clear"]; + delete tex["vampiric"]; + //delete tex["djule"]; } diff --git a/src/includes/State.hpp b/src/includes/State.hpp index bcfb365..0b212b8 100644 --- a/src/includes/State.hpp +++ b/src/includes/State.hpp @@ -23,6 +23,7 @@ class State void keyboard(); public: State(); + ~State(); void loop(); }; -- cgit v1.2.3