From 56e9be326eaecc3c36f38d3c2873f7c78a26740a Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 23 Sep 2018 15:26:24 +0800 Subject: [PATCH] Fix #3463 --- src/config/user_config.cpp | 10 +++++++--- src/config/user_config.hpp | 1 + src/network/server_config.cpp | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index c5cf6d8e4..1fdc6a97c 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -41,6 +41,7 @@ static std::vector all_params; #include "utils/string_utils.hpp" #include "utils/translation.hpp" +#include #include #include #include @@ -53,9 +54,12 @@ const int UserConfig::m_current_config_version = 8; // ---------------------------------------------------------------------------- UserConfigParam::~UserConfigParam() { - // Now we have server config param so we cannot do this anymore, - // esp all params are kept until the closing of stk anyway - //all_params.remove(this); + if (m_can_be_deleted) + { + auto it = std::find(all_params.begin(), all_params.end(), this); + if (it != all_params.end()) + all_params.erase(it); + } } // ~UserConfigParam // ---------------------------------------------------------------------------- diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index a43a4cca0..47b382709 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -66,6 +66,7 @@ class UserConfigParam { friend class GroupUserConfigParam; protected: + bool m_can_be_deleted = true; std::string m_param_name; std::string m_comment; public: diff --git a/src/network/server_config.cpp b/src/network/server_config.cpp index 80cbbea42..2dc6972bc 100644 --- a/src/network/server_config.cpp +++ b/src/network/server_config.cpp @@ -51,6 +51,7 @@ FloatServerConfigParam::FloatServerConfigParam(float default_value, const char* comment) : FloatUserConfigParam(param_name, comment) { + m_can_be_deleted = false; m_value = default_value; m_default_value = default_value; g_server_params.push_back(this); @@ -62,6 +63,7 @@ IntServerConfigParam::IntServerConfigParam(int default_value, const char* comment) : IntUserConfigParam(param_name, comment) { + m_can_be_deleted = false; m_value = default_value; m_default_value = default_value; g_server_params.push_back(this); @@ -73,6 +75,7 @@ BoolServerConfigParam::BoolServerConfigParam(bool default_value, const char* comment) : BoolUserConfigParam(param_name, comment) { + m_can_be_deleted = false; m_value = default_value; m_default_value = default_value; g_server_params.push_back(this); @@ -84,6 +87,7 @@ StringServerConfigParam::StringServerConfigParam(std::string default_value, const char* comment) : StringUserConfigParam(param_name, comment) { + m_can_be_deleted = false; m_value = default_value; m_default_value = default_value; g_server_params.push_back(this);