From 291022316a4a3c742be92abd0d2b94256df60143 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Sun, 3 Dec 2023 12:33:37 -0500 Subject: Update to Godot 4.2 Stable Release Fix compiledb Fix memory leak caused by LoadLocalisation::add_message's translations static variable --- extension/src/openvic-extension/singletons/GameSingleton.cpp | 5 ++++- extension/src/openvic-extension/singletons/LoadLocalisation.cpp | 1 - extension/src/openvic-extension/singletons/LoadLocalisation.hpp | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'extension/src/openvic-extension') diff --git a/extension/src/openvic-extension/singletons/GameSingleton.cpp b/extension/src/openvic-extension/singletons/GameSingleton.cpp index db3dd3f..4a80eb9 100644 --- a/extension/src/openvic-extension/singletons/GameSingleton.cpp +++ b/extension/src/openvic-extension/singletons/GameSingleton.cpp @@ -1,5 +1,7 @@ #include "GameSingleton.hpp" +#include + #include #include #include @@ -553,7 +555,8 @@ Error GameSingleton::load_defines_compatibility_mode(PackedStringArray const& fi UtilityFunctions::push_error("Failed to hardcoded defines!"); err = FAILED; } - if (!dataloader.load_localisation_files(LoadLocalisation::add_message)) { + auto add_message = std::bind_front(&LoadLocalisation::add_message, LoadLocalisation::get_singleton()); + if (!dataloader.load_localisation_files(add_message)) { UtilityFunctions::push_error("Failed to load localisation!"); err = FAILED; } diff --git a/extension/src/openvic-extension/singletons/LoadLocalisation.cpp b/extension/src/openvic-extension/singletons/LoadLocalisation.cpp index 96c67e8..3da8bc8 100644 --- a/extension/src/openvic-extension/singletons/LoadLocalisation.cpp +++ b/extension/src/openvic-extension/singletons/LoadLocalisation.cpp @@ -135,7 +135,6 @@ Error LoadLocalisation::load_localisation_dir(String const& dir_path) const { return err; } bool LoadLocalisation::add_message(std::string_view key, Dataloader::locale_t locale, std::string_view localisation) { - static Ref translations[Dataloader::_LocaleCount] = { nullptr }; Ref& translation = translations[locale]; if (translation.is_null()) { translation = _singleton->_get_translation(Dataloader::locale_names[locale]); diff --git a/extension/src/openvic-extension/singletons/LoadLocalisation.hpp b/extension/src/openvic-extension/singletons/LoadLocalisation.hpp index b093fdf..aeee076 100644 --- a/extension/src/openvic-extension/singletons/LoadLocalisation.hpp +++ b/extension/src/openvic-extension/singletons/LoadLocalisation.hpp @@ -10,6 +10,8 @@ namespace OpenVic { static inline LoadLocalisation* _singleton = nullptr; + godot::Ref translations[Dataloader::_LocaleCount]; + godot::Error _load_file(godot::String const& file_path, godot::Ref translation) const; godot::Ref _get_translation(godot::String const& locale) const; @@ -26,6 +28,6 @@ namespace OpenVic { godot::Error load_locale_dir(godot::String const& dir_path, godot::String const& locale) const; godot::Error load_localisation_dir(godot::String const& dir_path) const; - static bool add_message(std::string_view key, Dataloader::locale_t locale, std::string_view localisation); + bool add_message(std::string_view key, Dataloader::locale_t locale, std::string_view localisation); }; } -- cgit v1.2.3-56-ga3b1