Skip to content

Commit c5f773e

Browse files
committed
Fix editor potentially having multiple instances of the same subresource
1 parent 3cd3caa commit c5f773e

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

core/bind/core_bind.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ static const unsigned int MONTH_DAYS_TABLE[2][12] = {
6666
_ResourceLoader *_ResourceLoader::singleton = nullptr;
6767

6868
Ref<ResourceInteractiveLoader> _ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint, bool p_no_cache) {
69-
return ResourceLoader::load_interactive(p_path, p_type_hint, p_no_cache);
69+
return ResourceLoader::load_interactive(p_path, p_type_hint, p_no_cache, p_no_cache);
7070
}
7171

7272
RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache) {
7373
Error err = OK;
74-
RES ret = ResourceLoader::load(p_path, p_type_hint, p_no_cache, &err);
74+
RES ret = ResourceLoader::load(p_path, p_type_hint, p_no_cache, p_no_cache, &err);
7575

7676
ERR_FAIL_COND_V_MSG(err != OK, ret, "Error loading resource: '" + p_path + "'.");
7777
return ret;

core/io/resource_loader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void ResourceLoader::_remove_from_loading_map_and_thread(const String &p_path, T
335335
loading_map_mutex.unlock();
336336
}
337337

338-
RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
338+
RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, bool p_no_subresources_cache, Error *r_error) {
339339
if (r_error) {
340340
*r_error = ERR_CANT_OPEN;
341341
}
@@ -386,7 +386,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
386386
}
387387

388388
print_verbose("Loading resource: " + path);
389-
RES res = _load(path, local_path, p_type_hint, p_no_cache, r_error);
389+
RES res = _load(path, local_path, p_type_hint, p_no_subresources_cache, r_error);
390390

391391
if (res.is_null()) {
392392
if (!p_no_cache) {
@@ -452,7 +452,7 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
452452
return false;
453453
}
454454

455-
Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
455+
Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint, bool p_no_cache, bool p_no_subresources_cache, Error *r_error) {
456456
if (r_error) {
457457
*r_error = ERR_CANT_OPEN;
458458
}
@@ -497,7 +497,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
497497
continue;
498498
}
499499
found = true;
500-
Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(path, local_path, r_error, p_no_cache);
500+
Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(path, local_path, r_error, p_no_subresources_cache);
501501
if (ril.is_null()) {
502502
continue;
503503
}

core/io/resource_loader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ class ResourceLoader {
142142
static void _remove_from_loading_map_and_thread(const String &p_path, Thread::ID p_thread);
143143

144144
public:
145-
static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = nullptr);
146-
static RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = nullptr);
145+
static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, bool p_no_subresources_cache = false, Error *r_error = nullptr);
146+
static RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, bool p_no_subresources_cache = false, Error *r_error = nullptr);
147147
static bool exists(const String &p_path, const String &p_type_hint = "");
148148

149149
static void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions);

editor/editor_node.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3653,7 +3653,10 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
36533653
dependency_errors.clear();
36543654

36553655
Error err;
3656-
Ref<PackedScene> sdata = ResourceLoader::load(lpath, "", true, &err);
3656+
// Subresources must use cache since they may already be referenced by other scenes.
3657+
// Otherwise, main and inherited scenes would contain different instances of the same
3658+
// resource, leading to superfluously saved subresources in derived scenes.
3659+
Ref<PackedScene> sdata = ResourceLoader::load(lpath, "", true, false, &err);
36573660
if (!sdata.is_valid()) {
36583661
_dialog_display_load_error(lpath, err);
36593662
opening_prev = false;

0 commit comments

Comments
 (0)