Skip to content

Commit 0472bcb

Browse files
committed
Fix editor potentially having multiple instances of the same subresource
1 parent 42b054a commit 0472bcb

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

core/io/resource_loader.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ void ResourceLoader::_remove_from_loading_map_and_thread(const String &p_path, T
336336
}
337337

338338
RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
339+
return load(p_path, p_type_hint, p_no_cache, false, r_error);
340+
}
341+
342+
RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, bool p_no_subresources_cache, Error *r_error) {
339343
if (r_error) {
340344
*r_error = ERR_CANT_OPEN;
341345
}
@@ -386,7 +390,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
386390
}
387391

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

391395
if (res.is_null()) {
392396
if (!p_no_cache) {
@@ -453,6 +457,10 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
453457
}
454458

455459
Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
460+
return load_interactive(p_path, p_type_hint, p_no_cache, p_no_cache, r_error);
461+
}
462+
463+
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) {
456464
if (r_error) {
457465
*r_error = ERR_CANT_OPEN;
458466
}
@@ -497,7 +505,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
497505
continue;
498506
}
499507
found = true;
500-
Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(path, local_path, r_error, p_no_cache);
508+
Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(path, local_path, r_error, p_no_subresources_cache);
501509
if (ril.is_null()) {
502510
continue;
503511
}

core/io/resource_loader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ class ResourceLoader {
143143

144144
public:
145145
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 Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_type_hint, bool p_no_cache, bool p_no_subresources_cache, Error *r_error = nullptr);
146147
static RES load(const String &p_path, const String &p_type_hint = "", bool p_no_cache = false, Error *r_error = nullptr);
148+
static RES load(const String &p_path, const String &p_type_hint, bool p_no_cache, bool p_no_subresources_cache, Error *r_error = nullptr);
147149
static bool exists(const String &p_path, const String &p_type_hint = "");
148150

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

editor/editor_node.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_d
10021002
dependency_errors.clear();
10031003

10041004
Error err;
1005-
RES res = ResourceLoader::load(p_resource, "", false, &err);
1005+
RES res = ResourceLoader::load(p_resource, "", false, false, &err);
10061006
ERR_FAIL_COND_V(!res.is_valid(), ERR_CANT_OPEN);
10071007

10081008
if (!p_ignore_broken_deps && dependency_errors.has(p_resource)) {
@@ -3686,7 +3686,10 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
36863686
dependency_errors.clear();
36873687

36883688
Error err;
3689-
Ref<PackedScene> sdata = ResourceLoader::load(lpath, "", true, &err);
3689+
// Subresources must use cache since they may already be referenced by other scenes.
3690+
// Otherwise, main and inherited scenes would contain different instances of the same
3691+
// resource, leading to superfluously saved subresources in derived scenes.
3692+
Ref<PackedScene> sdata = ResourceLoader::load(lpath, "", true, false, &err);
36903693
if (!sdata.is_valid()) {
36913694
_dialog_display_load_error(lpath, err);
36923695
opening_prev = false;

0 commit comments

Comments
 (0)