mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-31 21:51:22 +00:00 
			
		
		
		
	Fix GDScriptCache to not remove scripts/scenes individually when clearing
				
					
				
			This commit is contained in:
		
							parent
							
								
									e9c7140cfa
								
							
						
					
					
						commit
						ff544df926
					
				
					 2 changed files with 21 additions and 10 deletions
				
			
		|  | @ -128,6 +128,10 @@ void GDScriptCache::move_script(const String &p_from, const String &p_to) { | ||||||
| 
 | 
 | ||||||
| 	MutexLock lock(singleton->mutex); | 	MutexLock lock(singleton->mutex); | ||||||
| 
 | 
 | ||||||
|  | 	if (singleton->cleared) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	for (KeyValue<String, HashSet<String>> &E : singleton->packed_scene_dependencies) { | 	for (KeyValue<String, HashSet<String>> &E : singleton->packed_scene_dependencies) { | ||||||
| 		if (E.value.has(p_from)) { | 		if (E.value.has(p_from)) { | ||||||
| 			E.value.insert(p_to); | 			E.value.insert(p_to); | ||||||
|  | @ -158,6 +162,10 @@ void GDScriptCache::remove_script(const String &p_path) { | ||||||
| 
 | 
 | ||||||
| 	MutexLock lock(singleton->mutex); | 	MutexLock lock(singleton->mutex); | ||||||
| 
 | 
 | ||||||
|  | 	if (singleton->cleared) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	for (KeyValue<String, HashSet<String>> &E : singleton->packed_scene_dependencies) { | 	for (KeyValue<String, HashSet<String>> &E : singleton->packed_scene_dependencies) { | ||||||
| 		if (!E.value.has(p_path)) { | 		if (!E.value.has(p_path)) { | ||||||
| 			continue; | 			continue; | ||||||
|  | @ -371,6 +379,10 @@ void GDScriptCache::clear_unreferenced_packed_scenes() { | ||||||
| 
 | 
 | ||||||
| 	MutexLock lock(singleton->mutex); | 	MutexLock lock(singleton->mutex); | ||||||
| 
 | 
 | ||||||
|  | 	if (singleton->cleared) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	for (KeyValue<String, HashSet<String>> &E : singleton->packed_scene_dependencies) { | 	for (KeyValue<String, HashSet<String>> &E : singleton->packed_scene_dependencies) { | ||||||
| 		if (E.value.size() > 0 || !ResourceLoader::is_imported(E.key)) { | 		if (E.value.size() > 0 || !ResourceLoader::is_imported(E.key)) { | ||||||
| 			continue; | 			continue; | ||||||
|  | @ -388,6 +400,11 @@ void GDScriptCache::clear() { | ||||||
| 
 | 
 | ||||||
| 	MutexLock lock(singleton->mutex); | 	MutexLock lock(singleton->mutex); | ||||||
| 
 | 
 | ||||||
|  | 	if (singleton->cleared) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 	singleton->cleared = true; | ||||||
|  | 
 | ||||||
| 	RBSet<Ref<GDScriptParserRef>> parser_map_refs; | 	RBSet<Ref<GDScriptParserRef>> parser_map_refs; | ||||||
| 	for (KeyValue<String, GDScriptParserRef *> &E : singleton->parser_map) { | 	for (KeyValue<String, GDScriptParserRef *> &E : singleton->parser_map) { | ||||||
| 		parser_map_refs.insert(E.value); | 		parser_map_refs.insert(E.value); | ||||||
|  | @ -417,7 +434,8 @@ GDScriptCache::GDScriptCache() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| GDScriptCache::~GDScriptCache() { | GDScriptCache::~GDScriptCache() { | ||||||
| 	destructing = true; | 	if (!cleared) { | ||||||
| 	clear(); | 		clear(); | ||||||
|  | 	} | ||||||
| 	singleton = nullptr; | 	singleton = nullptr; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -87,7 +87,7 @@ class GDScriptCache { | ||||||
| 
 | 
 | ||||||
| 	static GDScriptCache *singleton; | 	static GDScriptCache *singleton; | ||||||
| 
 | 
 | ||||||
| 	bool destructing = false; | 	bool cleared = false; | ||||||
| 
 | 
 | ||||||
| 	Mutex mutex; | 	Mutex mutex; | ||||||
| 
 | 
 | ||||||
|  | @ -104,13 +104,6 @@ public: | ||||||
| 	static Ref<PackedScene> get_packed_scene(const String &p_path, Error &r_error, const String &p_owner = ""); | 	static Ref<PackedScene> get_packed_scene(const String &p_path, Error &r_error, const String &p_owner = ""); | ||||||
| 	static void clear_unreferenced_packed_scenes(); | 	static void clear_unreferenced_packed_scenes(); | ||||||
| 
 | 
 | ||||||
| 	static bool is_destructing() { |  | ||||||
| 		if (singleton == nullptr) { |  | ||||||
| 			return true; |  | ||||||
| 		} |  | ||||||
| 		return singleton->destructing; |  | ||||||
| 	}; |  | ||||||
| 
 |  | ||||||
| 	static void clear(); | 	static void clear(); | ||||||
| 
 | 
 | ||||||
| 	GDScriptCache(); | 	GDScriptCache(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Adam Scott
						Adam Scott