From e290448fe3295b43f06f23eacb7a07cdc3d064a8 Mon Sep 17 00:00:00 2001 From: Abdulrahman Al Zeidi Date: Mon, 27 Feb 2023 02:44:23 +0000 Subject: Fix glTF mesh importer not freeing nodes correctly on import (cherry picked from commit 5e0641ea9af03491889d89f9bdac0785e5bc3158) --- .../gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp index 388c3ec740..2af716b867 100644 --- a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp +++ b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp @@ -70,7 +70,7 @@ Error GLTFDocumentExtensionConvertImporterMesh::import_post(Ref p_sta } queue.pop_front(); } - while (!queue.is_empty()) { + while (!delete_queue.is_empty()) { List::Element *E = delete_queue.front(); Node *node = E->get(); memdelete(node); -- cgit v1.2.3 From 466d226a4acc66fc1c1c4faf8d9da68e6c84fbda Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Tue, 21 Feb 2023 09:43:54 +0200 Subject: [TextServer] Ensure ICU data is initialised only one and cleaned only at exit. (cherry picked from commit 7f24433e15081044aa8bcc3a646ded5129048bf5) --- modules/text_server_adv/text_server_adv.cpp | 5 ++++- modules/text_server_adv/text_server_adv.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 22652daa24..007f439a89 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -334,6 +334,8 @@ _FORCE_INLINE_ bool is_connected_to_prev(char32_t p_chr, char32_t p_pchr) { /*************************************************************************/ +bool TextServerAdvanced::icu_data_loaded = false; + bool TextServerAdvanced::_has_feature(Feature p_feature) const { switch (p_feature) { case FEATURE_SIMPLE_LAYOUT: @@ -6599,5 +6601,6 @@ TextServerAdvanced::~TextServerAdvanced() { uset_close(allowed); allowed = nullptr; } - u_cleanup(); + + std::atexit(u_cleanup); } diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h index 02244a294e..f092fa8cca 100644 --- a/modules/text_server_adv/text_server_adv.h +++ b/modules/text_server_adv/text_server_adv.h @@ -158,7 +158,7 @@ class TextServerAdvanced : public TextServerExtension { // ICU support data. - bool icu_data_loaded = false; + static bool icu_data_loaded; mutable USet *allowed = nullptr; mutable USpoofChecker *sc_spoof = nullptr; mutable USpoofChecker *sc_conf = nullptr; -- cgit v1.2.3 From 048c252602aa9e21175b7e125dbcae204e303b1f Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Wed, 8 Mar 2023 19:46:55 +0100 Subject: Prevent cache corruption when saving resources in the editor (cherry picked from commit 496bd94c21dbda01fc7d9d0a108eecef21924024) --- editor/editor_node.cpp | 17 +++++++++++++++++ editor/editor_node.h | 1 + modules/gdscript/gdscript.cpp | 6 ++++-- 3 files changed, 22 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 6fcf092834..2834a086b8 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -1233,6 +1233,12 @@ void EditorNode::edit_resource(const Ref &p_resource) { void EditorNode::save_resource_in_path(const Ref &p_resource, const String &p_path) { editor_data.apply_changes_in_editors(); + + if (saving_resources_in_path.has(p_resource)) { + return; + } + saving_resources_in_path.insert(p_resource); + int flg = 0; if (EDITOR_GET("filesystem/on_save/compress_binary_resources")) { flg |= ResourceSaver::FLAG_COMPRESS; @@ -1247,10 +1253,16 @@ void EditorNode::save_resource_in_path(const Ref &p_resource, const St } else { show_accept(TTR("Error saving resource!"), TTR("OK")); } + + saving_resources_in_path.erase(p_resource); return; } ((Resource *)p_resource.ptr())->set_path(path); + saving_resources_in_path.erase(p_resource); + + _resource_saved(p_resource, path); + emit_signal(SNAME("resource_saved"), p_resource); editor_data.notify_resource_saved(p_resource); } @@ -6441,6 +6453,11 @@ void EditorNode::_renderer_selected(int p_which) { } void EditorNode::_resource_saved(Ref p_resource, const String &p_path) { + if (singleton->saving_resources_in_path.has(p_resource)) { + // This is going to be handled by save_resource_in_path when the time is right. + return; + } + if (EditorFileSystem::get_singleton()) { EditorFileSystem::get_singleton()->update_file(p_path); } diff --git a/editor/editor_node.h b/editor/editor_node.h index 8ad5969249..6a9d052791 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -485,6 +485,7 @@ private: Object *current = nullptr; Ref saving_resource; + HashSet> saving_resources_in_path; uint64_t update_spinner_step_msec = 0; uint64_t update_spinner_step_frame = 0; diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index b6caefbdb5..1a1d021dbc 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1010,12 +1010,14 @@ void GDScript::_bind_methods() { } void GDScript::set_path(const String &p_path, bool p_take_over) { - String old_path = path; if (is_root_script()) { Script::set_path(p_path, p_take_over); } - this->path = p_path; + + String old_path = path; + path = p_path; GDScriptCache::move_script(old_path, p_path); + for (KeyValue> &kv : subclasses) { kv.value->set_path(p_path, p_take_over); } -- cgit v1.2.3 From d83245f2f94410768016899df91ce3134091bb7b Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Fri, 10 Mar 2023 09:10:12 +0200 Subject: [TextServer] Add invalid font scaling check, restrict Linux/BSD system fonts lookup to TrueType/CFF only. (cherry picked from commit 8d501a2dc31f3bef6d5a7f6b0d060c8915082011) --- modules/text_server_adv/text_server_adv.cpp | 4 +- modules/text_server_fb/text_server_fb.cpp | 4 +- platform/linuxbsd/os_linuxbsd.cpp | 137 +++++++++++++++------------- 3 files changed, 79 insertions(+), 66 deletions(-) (limited to 'modules') diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 007f439a89..50aea3da2e 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -1386,7 +1386,9 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f FT_Select_Size(fd->face, best_match); } else { FT_Set_Pixel_Sizes(fd->face, 0, double(fd->size.x * fd->oversampling)); - fd->scale = ((double)fd->size.x * fd->oversampling) / (double)fd->face->size->metrics.y_ppem; + if (fd->face->size->metrics.y_ppem != 0) { + fd->scale = ((double)fd->size.x * fd->oversampling) / (double)fd->face->size->metrics.y_ppem; + } } fd->hb_handle = hb_ft_font_create(fd->face, nullptr); diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index 240ae8310a..d67ae6b45b 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -825,7 +825,9 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_cache_for_size(FontFallback *p_f FT_Select_Size(fd->face, best_match); } else { FT_Set_Pixel_Sizes(fd->face, 0, Math::round(fd->size.x * fd->oversampling)); - fd->scale = ((double)fd->size.x * fd->oversampling) / (double)fd->face->size->metrics.y_ppem; + if (fd->face->size->metrics.y_ppem != 0) { + fd->scale = ((double)fd->size.x * fd->oversampling) / (double)fd->face->size->metrics.y_ppem; + } } fd->ascent = (fd->face->size->metrics.ascender / 64.0) / fd->oversampling * fd->scale; diff --git a/platform/linuxbsd/os_linuxbsd.cpp b/platform/linuxbsd/os_linuxbsd.cpp index 54bb34ef73..88c3d2cc14 100644 --- a/platform/linuxbsd/os_linuxbsd.cpp +++ b/platform/linuxbsd/os_linuxbsd.cpp @@ -677,40 +677,45 @@ Vector OS_LinuxBSD::get_system_font_path_for_text(const String &p_font_n } Vector ret; - FcPattern *pattern = FcPatternCreate(); - if (pattern) { - FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast(p_font_name.utf8().get_data())); - FcPatternAddInteger(pattern, FC_WEIGHT, _weight_to_fc(p_weight)); - FcPatternAddInteger(pattern, FC_WIDTH, _stretch_to_fc(p_stretch)); - FcPatternAddInteger(pattern, FC_SLANT, p_italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN); - - FcCharSet *char_set = FcCharSetCreate(); - for (int i = 0; i < p_text.size(); i++) { - FcCharSetAddChar(char_set, p_text[i]); - } - FcPatternAddCharSet(pattern, FC_CHARSET, char_set); - - FcLangSet *lang_set = FcLangSetCreate(); - FcLangSetAdd(lang_set, reinterpret_cast(p_locale.utf8().get_data())); - FcPatternAddLangSet(pattern, FC_LANG, lang_set); - - FcConfigSubstitute(0, pattern, FcMatchPattern); - FcDefaultSubstitute(pattern); - - FcResult result; - FcPattern *match = FcFontMatch(0, pattern, &result); - if (match) { - char *file_name = nullptr; - if (FcPatternGetString(match, FC_FILE, 0, reinterpret_cast(&file_name)) == FcResultMatch) { - if (file_name) { - ret.push_back(String::utf8(file_name)); + static const char *allowed_formats[] = { "TrueType", "CFF" }; + for (size_t i = 0; i < sizeof(allowed_formats) / sizeof(const char *); i++) { + FcPattern *pattern = FcPatternCreate(); + if (pattern) { + FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); + FcPatternAddString(pattern, FC_FONTFORMAT, reinterpret_cast(allowed_formats[i])); + FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast(p_font_name.utf8().get_data())); + FcPatternAddInteger(pattern, FC_WEIGHT, _weight_to_fc(p_weight)); + FcPatternAddInteger(pattern, FC_WIDTH, _stretch_to_fc(p_stretch)); + FcPatternAddInteger(pattern, FC_SLANT, p_italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN); + + FcCharSet *char_set = FcCharSetCreate(); + for (int j = 0; j < p_text.size(); j++) { + FcCharSetAddChar(char_set, p_text[j]); + } + FcPatternAddCharSet(pattern, FC_CHARSET, char_set); + + FcLangSet *lang_set = FcLangSetCreate(); + FcLangSetAdd(lang_set, reinterpret_cast(p_locale.utf8().get_data())); + FcPatternAddLangSet(pattern, FC_LANG, lang_set); + + FcConfigSubstitute(0, pattern, FcMatchPattern); + FcDefaultSubstitute(pattern); + + FcResult result; + FcPattern *match = FcFontMatch(0, pattern, &result); + if (match) { + char *file_name = nullptr; + if (FcPatternGetString(match, FC_FILE, 0, reinterpret_cast(&file_name)) == FcResultMatch) { + if (file_name) { + ret.push_back(String::utf8(file_name)); + } } + FcPatternDestroy(match); } - FcPatternDestroy(match); + FcPatternDestroy(pattern); + FcCharSetDestroy(char_set); + FcLangSetDestroy(lang_set); } - FcPatternDestroy(pattern); - FcCharSetDestroy(char_set); - FcLangSetDestroy(lang_set); } return ret; @@ -725,47 +730,51 @@ String OS_LinuxBSD::get_system_font_path(const String &p_font_name, int p_weight ERR_FAIL_V_MSG(String(), "Unable to load fontconfig, system font support is disabled."); } - String ret; - FcPattern *pattern = FcPatternCreate(); - if (pattern) { - bool allow_substitutes = (p_font_name.to_lower() == "sans-serif") || (p_font_name.to_lower() == "serif") || (p_font_name.to_lower() == "monospace") || (p_font_name.to_lower() == "cursive") || (p_font_name.to_lower() == "fantasy"); - - FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); - FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast(p_font_name.utf8().get_data())); - FcPatternAddInteger(pattern, FC_WEIGHT, _weight_to_fc(p_weight)); - FcPatternAddInteger(pattern, FC_WIDTH, _stretch_to_fc(p_stretch)); - FcPatternAddInteger(pattern, FC_SLANT, p_italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN); - - FcConfigSubstitute(0, pattern, FcMatchPattern); - FcDefaultSubstitute(pattern); - - FcResult result; - FcPattern *match = FcFontMatch(0, pattern, &result); - if (match) { - if (!allow_substitutes) { - char *family_name = nullptr; - if (FcPatternGetString(match, FC_FAMILY, 0, reinterpret_cast(&family_name)) == FcResultMatch) { - if (family_name && String::utf8(family_name).to_lower() != p_font_name.to_lower()) { + static const char *allowed_formats[] = { "TrueType", "CFF" }; + for (size_t i = 0; i < sizeof(allowed_formats) / sizeof(const char *); i++) { + FcPattern *pattern = FcPatternCreate(); + if (pattern) { + bool allow_substitutes = (p_font_name.to_lower() == "sans-serif") || (p_font_name.to_lower() == "serif") || (p_font_name.to_lower() == "monospace") || (p_font_name.to_lower() == "cursive") || (p_font_name.to_lower() == "fantasy"); + + FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); + FcPatternAddString(pattern, FC_FONTFORMAT, reinterpret_cast(allowed_formats[i])); + FcPatternAddString(pattern, FC_FAMILY, reinterpret_cast(p_font_name.utf8().get_data())); + FcPatternAddInteger(pattern, FC_WEIGHT, _weight_to_fc(p_weight)); + FcPatternAddInteger(pattern, FC_WIDTH, _stretch_to_fc(p_stretch)); + FcPatternAddInteger(pattern, FC_SLANT, p_italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN); + + FcConfigSubstitute(0, pattern, FcMatchPattern); + FcDefaultSubstitute(pattern); + + FcResult result; + FcPattern *match = FcFontMatch(0, pattern, &result); + if (match) { + if (!allow_substitutes) { + char *family_name = nullptr; + if (FcPatternGetString(match, FC_FAMILY, 0, reinterpret_cast(&family_name)) == FcResultMatch) { + if (family_name && String::utf8(family_name).to_lower() != p_font_name.to_lower()) { + FcPatternDestroy(match); + FcPatternDestroy(pattern); + continue; + } + } + } + char *file_name = nullptr; + if (FcPatternGetString(match, FC_FILE, 0, reinterpret_cast(&file_name)) == FcResultMatch) { + if (file_name) { + String ret = String::utf8(file_name); FcPatternDestroy(match); FcPatternDestroy(pattern); - - return String(); + return ret; } } + FcPatternDestroy(match); } - char *file_name = nullptr; - if (FcPatternGetString(match, FC_FILE, 0, reinterpret_cast(&file_name)) == FcResultMatch) { - if (file_name) { - ret = String::utf8(file_name); - } - } - - FcPatternDestroy(match); + FcPatternDestroy(pattern); } - FcPatternDestroy(pattern); } - return ret; + return String(); #else ERR_FAIL_V_MSG(String(), "Godot was compiled without fontconfig, system font support is disabled."); #endif -- cgit v1.2.3 From 3c2e952889e5a75b97b0750dc714af181a79eeb7 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Tue, 7 Mar 2023 19:10:54 +0100 Subject: Prevent crashing on startup if project has scripted theme types Also avoid order of operation conflicts by moving C# binding generation hook to main.cpp (cherry picked from commit 8402927d3f55f06651045a6a94e163327e26c2ab) --- main/main.cpp | 17 ++++++++++++++++- modules/mono/csharp_script.cpp | 8 -------- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'modules') diff --git a/main/main.cpp b/main/main.cpp index b15588e700..f4d2dbef52 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -108,6 +108,10 @@ #include "modules/modules_enabled.gen.h" // For mono. +#if defined(MODULE_MONO_ENABLED) && defined(TOOLS_ENABLED) +#include "modules/mono/editor/bindings_generator.h" +#endif + /* Static members */ // Singletons @@ -312,7 +316,6 @@ void finalize_navigation_server() { void initialize_theme_db() { theme_db = memnew(ThemeDB); - theme_db->initialize_theme(); } void finalize_theme_db() { @@ -532,6 +535,7 @@ Error Main::test_setup() { // Theme needs modules to be initialized so that sub-resources can be loaded. initialize_theme_db(); + theme_db->initialize_theme(); register_scene_singletons(); ERR_FAIL_COND_V(TextServerManager::get_singleton()->get_interface_count() == 0, ERR_CANT_CREATE); @@ -2314,6 +2318,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { register_platform_apis(); // Theme needs modules to be initialized so that sub-resources can be loaded. + // Default theme is initialized later, after ScriptServer is ready. initialize_theme_db(); register_scene_singletons(); @@ -2341,8 +2346,18 @@ Error Main::setup2(Thread::ID p_main_tid_override) { // This loads global classes, so it must happen before custom loaders and savers are registered ScriptServer::init_languages(); + theme_db->initialize_theme(); audio_server->load_default_bus_layout(); +#if defined(MODULE_MONO_ENABLED) && defined(TOOLS_ENABLED) + // Hacky to have it here, but we don't have good facility yet to let modules + // register command line options to call at the right time. This needs to happen + // after init'ing the ScriptServer, but also after init'ing the ThemeDB, + // for the C# docs generation in the bindings. + List cmdline_args = OS::get_singleton()->get_cmdline_args(); + BindingsGenerator::handle_cmdline_args(cmdline_args); +#endif + if (use_debug_profiler && EngineDebugger::is_active()) { // Start the "scripts" profiler, used in local debugging. // We could add more, and make the CLI arg require a comma-separated list of profilers. diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 872e803b9c..9159f308a2 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -42,7 +42,6 @@ #ifdef TOOLS_ENABLED #include "core/os/keyboard.h" -#include "editor/bindings_generator.h" #include "editor/editor_internal_calls.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" @@ -102,13 +101,6 @@ void CSharpLanguage::init() { } #endif -#if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) - // Generate the bindings here, before loading assemblies. The Godot assemblies - // may be missing if the glue wasn't generated yet in order to build them. - List cmdline_args = OS::get_singleton()->get_cmdline_args(); - BindingsGenerator::handle_cmdline_args(cmdline_args); -#endif - GLOBAL_DEF("dotnet/project/assembly_name", ""); #ifdef TOOLS_ENABLED GLOBAL_DEF("dotnet/project/solution_directory", ""); -- cgit v1.2.3 From 0112862e70819f700fd86104a136795fcbe1c80e Mon Sep 17 00:00:00 2001 From: RedworkDE <10944644+RedworkDE@users.noreply.github.com> Date: Tue, 28 Feb 2023 22:08:19 +0100 Subject: C#: Fix crash when errors occur before language initialization. (cherry picked from commit c0ebc281360c7df1acae4b0510d8310573491acc) --- modules/mono/csharp_script.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 9159f308a2..aad8ab9a57 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -581,7 +581,7 @@ Vector CSharpLanguage::debug_get_current_stack_info() _recursion_flag_ = false; }; - if (!gdmono->is_runtime_initialized()) { + if (!gdmono || !gdmono->is_runtime_initialized()) { return Vector(); } @@ -671,6 +671,7 @@ void CSharpLanguage::reload_tool_script(const Ref