From ff544df926d90724f2dbb6ef53667a1ee2ecdbb5 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Sat, 10 Dec 2022 12:48:07 -0500 Subject: [PATCH] Fix `GDScriptCache` to not remove scripts/scenes individually when clearing --- modules/gdscript/gdscript_cache.cpp | 22 ++++++++++++++++++++-- modules/gdscript/gdscript_cache.h | 9 +-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/modules/gdscript/gdscript_cache.cpp b/modules/gdscript/gdscript_cache.cpp index 1df7757082b..1dc5e335a0c 100644 --- a/modules/gdscript/gdscript_cache.cpp +++ b/modules/gdscript/gdscript_cache.cpp @@ -128,6 +128,10 @@ void GDScriptCache::move_script(const String &p_from, const String &p_to) { MutexLock lock(singleton->mutex); + if (singleton->cleared) { + return; + } + for (KeyValue> &E : singleton->packed_scene_dependencies) { if (E.value.has(p_from)) { E.value.insert(p_to); @@ -158,6 +162,10 @@ void GDScriptCache::remove_script(const String &p_path) { MutexLock lock(singleton->mutex); + if (singleton->cleared) { + return; + } + for (KeyValue> &E : singleton->packed_scene_dependencies) { if (!E.value.has(p_path)) { continue; @@ -371,6 +379,10 @@ void GDScriptCache::clear_unreferenced_packed_scenes() { MutexLock lock(singleton->mutex); + if (singleton->cleared) { + return; + } + for (KeyValue> &E : singleton->packed_scene_dependencies) { if (E.value.size() > 0 || !ResourceLoader::is_imported(E.key)) { continue; @@ -388,6 +400,11 @@ void GDScriptCache::clear() { MutexLock lock(singleton->mutex); + if (singleton->cleared) { + return; + } + singleton->cleared = true; + RBSet> parser_map_refs; for (KeyValue &E : singleton->parser_map) { parser_map_refs.insert(E.value); @@ -417,7 +434,8 @@ GDScriptCache::GDScriptCache() { } GDScriptCache::~GDScriptCache() { - destructing = true; - clear(); + if (!cleared) { + clear(); + } singleton = nullptr; } diff --git a/modules/gdscript/gdscript_cache.h b/modules/gdscript/gdscript_cache.h index e7e1901d5de..0ee269f96c2 100644 --- a/modules/gdscript/gdscript_cache.h +++ b/modules/gdscript/gdscript_cache.h @@ -87,7 +87,7 @@ class GDScriptCache { static GDScriptCache *singleton; - bool destructing = false; + bool cleared = false; Mutex mutex; @@ -104,13 +104,6 @@ public: static Ref get_packed_scene(const String &p_path, Error &r_error, const String &p_owner = ""); static void clear_unreferenced_packed_scenes(); - static bool is_destructing() { - if (singleton == nullptr) { - return true; - } - return singleton->destructing; - }; - static void clear(); GDScriptCache();