From: NilsForssen Date: Mon, 11 Dec 2023 07:54:53 +0000 (+0100) Subject: Fixed memory leak X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=be81f8f9ef57a5328d38303139dce86ef76901a9;p=TDDC76_proj.git Fixed memory leak --- diff --git a/assets/highscore.csv b/assets/highscore.csv index b569f55..39e2483 100644 --- a/assets/highscore.csv +++ b/assets/highscore.csv @@ -1,4 +1,5 @@ +, 9 +Nils, 6 Nisseboi, 5 Lukas is KUNG, 5 NissePisse, 4 -Nils, 1 diff --git a/src/GameOver_menu.cc b/src/GameOver_menu.cc index f298b6b..9838a9f 100644 --- a/src/GameOver_menu.cc +++ b/src/GameOver_menu.cc @@ -42,7 +42,7 @@ GameOver_menu::GameOver_menu(int const points, json& params) : data{} { - data = std::move(params); + data = params; texture.loadFromFile(data["gameover_menu"]["texture"]); sprite.setTexture(texture); diff --git a/src/Main_enemy.cc b/src/Main_enemy.cc index 52dcc25..b9481aa 100644 --- a/src/Main_enemy.cc +++ b/src/Main_enemy.cc @@ -55,6 +55,7 @@ void Main_enemy::update(Context& context) } else { + Game_state* game = static_cast(context.current_state.get()); if ((game->bottles).size() != 0) { diff --git a/src/Pause_menu.cc b/src/Pause_menu.cc index 8f51a29..7c14e63 100644 --- a/src/Pause_menu.cc +++ b/src/Pause_menu.cc @@ -84,7 +84,7 @@ void Pause_menu::update(Context& context) else if (menu) { context.next_state = std::make_unique(data); - context.saved_game.release(); + delete context.saved_game.release(); } // changes color on text depending on selection diff --git a/src/Scoreboard_menu.cc b/src/Scoreboard_menu.cc index 33fc74b..0c234de 100644 --- a/src/Scoreboard_menu.cc +++ b/src/Scoreboard_menu.cc @@ -31,7 +31,7 @@ Scoreboard_menu::Scoreboard_menu(json& params) : data{} { - data = std::move(params); + data = params; texture.loadFromFile(data["scoreboard_menu"]["texture"]); sprite.setTexture(texture); diff --git a/src/Start_menu.cc b/src/Start_menu.cc index 1531c51..65cd9c2 100644 --- a/src/Start_menu.cc +++ b/src/Start_menu.cc @@ -30,7 +30,7 @@ Start_menu::Start_menu(json& params) : data{} { - data = std::move(params); + data = params; //sprite texture.loadFromFile(data["start_menu"]["texture"]); diff --git a/src/States.cc b/src/States.cc index 65b46eb..603cc7c 100644 --- a/src/States.cc +++ b/src/States.cc @@ -33,7 +33,7 @@ Game_state::Game_state(json& params) : data{} { - data = std::move(params); + data = params; sf::Texture main_enemy_texture; sf::Texture sack_texture; sf::Texture player_texture; @@ -82,6 +82,16 @@ void Game_state::update(Context &context) player->update(context); helper->update(context); + enemy->update(context); + game_map->update(player->get_collected(), points, remaining_time); + if (yf != nullptr) + { + yf->update(context); + } + if(bike != nullptr) + { + bike->update(context); + } // Handle collision @@ -174,16 +184,6 @@ void Game_state::update(Context &context) bike = std::make_unique(bike_texture, data["bike_enemy"]); time_since_last_bike = 0; } - enemy->update(context); - game_map->update(player->get_collected(), points, remaining_time); - if (yf != nullptr) - { - yf->update(context); - } - if(bike != nullptr) - { - bike->update(context); - } } void Game_state::render(sf::RenderWindow &window) const