summaryrefslogtreecommitdiff
path: root/modules/gdscript/gdscript_cache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/gdscript_cache.cpp')
-rw-r--r--modules/gdscript/gdscript_cache.cpp51
1 files changed, 40 insertions, 11 deletions
diff --git a/modules/gdscript/gdscript_cache.cpp b/modules/gdscript/gdscript_cache.cpp
index 021504f242..d1467eea95 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<String, HashSet<String>> &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<String, HashSet<String>> &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<String, HashSet<String>> &E : singleton->packed_scene_dependencies) {
if (E.value.size() > 0 || !ResourceLoader::is_imported(E.key)) {
continue;
@@ -381,15 +393,20 @@ void GDScriptCache::clear_unreferenced_packed_scenes() {
}
}
-GDScriptCache::GDScriptCache() {
- singleton = this;
-}
+void GDScriptCache::clear() {
+ if (singleton == nullptr) {
+ return;
+ }
-GDScriptCache::~GDScriptCache() {
- destructing = true;
+ MutexLock lock(singleton->mutex);
+
+ if (singleton->cleared) {
+ return;
+ }
+ singleton->cleared = true;
RBSet<Ref<GDScriptParserRef>> parser_map_refs;
- for (KeyValue<String, GDScriptParserRef *> &E : parser_map) {
+ for (KeyValue<String, GDScriptParserRef *> &E : singleton->parser_map) {
parser_map_refs.insert(E.value);
}
@@ -398,13 +415,25 @@ GDScriptCache::~GDScriptCache() {
E->clear();
}
+ singleton->packed_scene_dependencies.clear();
+ singleton->packed_scene_cache.clear();
+
parser_map_refs.clear();
- parser_map.clear();
- shallow_gdscript_cache.clear();
- full_gdscript_cache.clear();
+ singleton->parser_map.clear();
+ singleton->shallow_gdscript_cache.clear();
+ singleton->full_gdscript_cache.clear();
- packed_scene_cache.clear();
- packed_scene_dependencies.clear();
+ singleton->packed_scene_cache.clear();
+ singleton->packed_scene_dependencies.clear();
+}
+GDScriptCache::GDScriptCache() {
+ singleton = this;
+}
+
+GDScriptCache::~GDScriptCache() {
+ if (!cleared) {
+ clear();
+ }
singleton = nullptr;
}