Fixed memory leak
authorNilsForssen <forssennils@gmail.com>
Mon, 11 Dec 2023 07:54:53 +0000 (08:54 +0100)
committerNilsForssen <forssennils@gmail.com>
Mon, 11 Dec 2023 07:54:53 +0000 (08:54 +0100)
assets/highscore.csv
src/GameOver_menu.cc
src/Main_enemy.cc
src/Pause_menu.cc
src/Scoreboard_menu.cc
src/Start_menu.cc
src/States.cc

index b569f5551707d493a3bab745667ee2f39afcd892..39e24836db39ebfbe02129f33e97e11ab056e859 100644 (file)
@@ -1,4 +1,5 @@
+, 9
+Nils, 6
 Nisseboi, 5
 Lukas is KUNG, 5
 NissePisse, 4
-Nils, 1
index f298b6b5fbaa1f2046304ef56999858cd051c0de..9838a9f57e4e50a3a768b0ec9ddbf89788d7847a 100644 (file)
@@ -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);
 
index 52dcc25d3965d2578904b1ecd606fd1f80b2d3f0..b9481aabdab3f786126877f89946c23363c2581a 100644 (file)
@@ -55,6 +55,7 @@ void Main_enemy::update(Context& context)
     }
     else
     {
+        
         Game_state* game = static_cast<Game_state*>(context.current_state.get());
         if ((game->bottles).size() != 0)
         {
index 8f51a2985d66183cdd04a114a9e72fc3702e6a2e..7c14e63dc1c6ec571088865aee112a7d4ab2f2d1 100644 (file)
@@ -84,7 +84,7 @@ void Pause_menu::update(Context& context)
     else if (menu)
     {
         context.next_state = std::make_unique<Start_menu>(data);
-        context.saved_game.release();
+        delete context.saved_game.release();
     }
  
     // changes color on text depending on selection
index 33fc74b690aad197a90e5ffddf03e2c9f5c928f1..0c234de941f4be584a77abf4a6e2bdda32db6d13 100644 (file)
@@ -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);
 
index 1531c519bcf96c6e9b2ec1d7f402f7e87601a96e..65cd9c272db0c7849bfbec7115708d73a2285c95 100644 (file)
@@ -30,7 +30,7 @@ Start_menu::Start_menu(json& params) :
 
     data{}
 {   
-    data = std::move(params);
+    data = params;
                 
     //sprite
     texture.loadFromFile(data["start_menu"]["texture"]);
index 65b46ebfd2ef0a9565c8010e3f7fb5f4ae75be99..603cc7c82f0ef572e7499315e42156dd5fa860ff 100644 (file)
@@ -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_enemy>(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