From 0e793e0c12d16e7f0af216dade6a7844ba55f839 Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Wed, 2 Oct 2019 09:17:53 +0200 Subject: [PATCH] Fixed memory management for achievements (#4381) Fixes #4380 --- src/map/achievement.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/map/achievement.cpp b/src/map/achievement.cpp index b7b4236c75..5159f6c62c 100644 --- a/src/map/achievement.cpp +++ b/src/map/achievement.cpp @@ -891,9 +891,28 @@ static bool achievement_update_objectives(struct map_session_data *sd, std::shar break; } - if (isNew) { - if (!(entry = achievement_add(sd, ad->achievement_id))) - return false; // Failed to add achievement + if( isNew ){ + // Always add the achievement if it was completed + bool hasCounter = complete; + + // If it was not completed + if( !hasCounter ){ + // Check if it has a counter + for( int counter : current_count ){ + if( counter != 0 ){ + hasCounter = true; + break; + } + } + } + + if( hasCounter ){ + if( !( entry = achievement_add( sd, ad->achievement_id ) ) ){ + return false; // Failed to add achievement + } + }else{ + changed = false; + } } if (changed) {