Skip to content

Commit 7ec6e85

Browse files
committed
Make GDScriptCache clearable multiple times
Fixes refactor tests memory leaks.
1 parent 8329d4f commit 7ec6e85

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

modules/gdscript/gdscript_cache.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void GDScriptCache::move_script(const String &p_from, const String &p_to) {
159159

160160
MutexLock lock(singleton->mutex);
161161

162-
if (singleton->cleared) {
162+
if (singleton->clearing) {
163163
return;
164164
}
165165

@@ -183,7 +183,7 @@ void GDScriptCache::remove_script(const String &p_path) {
183183

184184
MutexLock lock(singleton->mutex);
185185

186-
if (singleton->cleared) {
186+
if (singleton->clearing) {
187187
return;
188188
}
189189

@@ -451,10 +451,10 @@ void GDScriptCache::clear() {
451451

452452
MutexLock lock(singleton->mutex);
453453

454-
if (singleton->cleared) {
454+
if (singleton->clearing) {
455455
return;
456456
}
457-
singleton->cleared = true;
457+
singleton->clearing = true;
458458

459459
singleton->parser_inverse_dependencies.clear();
460460

@@ -486,14 +486,16 @@ void GDScriptCache::clear() {
486486
singleton->shallow_gdscript_cache.clear();
487487
singleton->full_gdscript_cache.clear();
488488
singleton->static_gdscript_cache.clear();
489+
490+
singleton->clearing = false;
489491
}
490492

491493
GDScriptCache::GDScriptCache() {
492494
singleton = this;
493495
}
494496

495497
GDScriptCache::~GDScriptCache() {
496-
if (!cleared) {
498+
if (!clearing) {
497499
clear();
498500
}
499501
singleton = nullptr;

modules/gdscript/gdscript_cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class GDScriptCache {
9494

9595
static GDScriptCache *singleton;
9696

97-
bool cleared = false;
97+
bool clearing = false;
9898

9999
public:
100100
static const int BINARY_MUTEX_TAG = 2;

modules/gdscript/tests/gdscript_test_runner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ void init_language() {
183183
}
184184

185185
void finish_language() {
186+
GDScriptCache::clear();
186187
GDScriptLanguage::get_singleton()->finish();
187188
ScriptServer::global_classes_clear();
188189
}

0 commit comments

Comments
 (0)