Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Fix sub-resource storing the wrong index in cache #49625

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions scene/resources/resource_format_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,8 @@ Error ResourceInteractiveLoaderText::_parse_sub_resource(VariantParser::Stream *

int index = token.value;

String path = local_path + "::" + itos(index);

if (!ignore_resource_parsing) {
if (!ResourceCache::has(path)) {
r_err_str = "Can't load cached sub-resource: " + path;
return ERR_PARSE_ERROR;
}

r_res = RES(ResourceCache::get(path));
} else {
r_res = RES();
}
ERR_FAIL_COND_V(!int_resources.has(index), ERR_INVALID_PARAMETER);
r_res = int_resources[index];

VariantParser::get_token(p_stream, token, line, r_err_str);
if (token.type != VariantParser::TK_PARENTHESIS_CLOSE) {
Expand Down Expand Up @@ -425,7 +415,6 @@ Error ResourceInteractiveLoaderText::poll() {
ResourceLoader::notify_dependency_error(local_path, path, type);
}
} else {
resource_cache.push_back(res);
#ifdef TOOLS_ENABLED
//remember ID for saving
res->set_id_for_path(local_path, index);
Expand Down Expand Up @@ -466,12 +455,16 @@ Error ResourceInteractiveLoaderText::poll() {

String path = local_path + "::" + itos(id);

//bool exists=ResourceCache::has(path);

Ref<Resource> res;

if (!ResourceCache::has(path)) { //only if it doesn't exist
bool do_assign = false;

if (ResourceCache::has(path)) {
//cached, do not assign
Resource *r = ResourceCache::get(path);
res = Ref<Resource>(r);
} else {
//create
Object *obj = ClassDB::instance(type);
if (!obj) {
error_text += "Can't create sub resource of type: " + type;
Expand All @@ -489,8 +482,13 @@ Error ResourceInteractiveLoaderText::poll() {
}

res = Ref<Resource>(r);
resource_cache.push_back(res);
do_assign = true;
}

int_resources[id] = res; //always assign int resources
if (do_assign) {
res->set_path(path);
res->set_subindex(id);
}

resource_current++;
Expand All @@ -507,7 +505,7 @@ Error ResourceInteractiveLoaderText::poll() {
}

if (assign != String()) {
if (res.is_valid()) {
if (do_assign) {
res->set(assign, value);
}
//it's assignment
Expand Down
2 changes: 1 addition & 1 deletion scene/resources/resource_format_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ResourceInteractiveLoaderText : public ResourceInteractiveLoader {
//Map<String,String> remaps;

Map<int, ExtResource> ext_resources;
Map<int, RES> int_resources;

int resources_total;
int resource_current;
Expand Down Expand Up @@ -100,7 +101,6 @@ class ResourceInteractiveLoaderText : public ResourceInteractiveLoader {

friend class ResourceFormatLoaderText;

List<RES> resource_cache;
Error error;

RES resource;
Expand Down