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

Fix sub-resource IDs resetting when preloaded #72257

Merged

Conversation

KoBeWi
Copy link
Member

@KoBeWi KoBeWi commented Jan 28, 2023

Probably fixes #62258, idk what the issue is about at this point

I had a case in my project where I had a scene A preloading scene B. If I opened A first and then opened B, all B's sub-resource IDs would reset and the built-in script would show as [unsaved][*]. It might be the clue of all sub-resource issues reported in the issue.

The fix I did is not probably correct (the code seems to have been like this for a very long time, so changing it might have some unwanted side-effects), but it fixes the issue.

EDIT:
I came upon this comment
#71171 (comment)
which basically confirms that it isn't the right fix. But if the cache is ignored, loading the same resource again should replace the resource from ignored load (to make sure it has a path this time).

@KoBeWi KoBeWi added this to the 4.0 milestone Jan 28, 2023
@akien-mga
Copy link
Member

Needs rebase to pass CI, I fixed the GDScript test error.

@KoBeWi KoBeWi force-pushed the potential_fix_or_maybe_not_who_knows branch from 28682c1 to 86049dc Compare January 28, 2023 16:06
@YuriSizov YuriSizov requested review from reduz and a team January 31, 2023 15:46
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tentatively approving to keep track of it as high priority :) But still needs @reduz to check it.

@reduz
Copy link
Member

reduz commented Feb 1, 2023

The problem is that, in many cases, we use CACHE_IGNORE to convert resources on background (on the exporter, as an example) and this change will break the ones currently loaded and edited.

I think the right fix is a bit simpler here, just change this code:

if (do_assign && cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
	res->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE);
	res->set_scene_unique_id(id);
}

by

if (do_assign && cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
	res->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE);
}
res->set_scene_unique_id(id);

This way, when the resource is re-saved it will keep the unique ID, but you don't necessarily kill the existing resource when using the CACHE_IGNORE mode.

@reduz
Copy link
Member

reduz commented Feb 1, 2023

After further discussion, it appears that what we need here is to separate the resource cache and the subresource cache modes in the ResourceLoader::load function. I will work on a PR for this soon.

@KoBeWi
Copy link
Member Author

KoBeWi commented Feb 1, 2023

After some investigation, the original issue is caused by this line:

scene->set_path(p_path);

Resource loaded with CACHE_MODE_IGNORE takes over a path and causes id reset. The solution mentioned in the above comment would fix it, but I think this is not really a correct behavior, idk.

@KoBeWi
Copy link
Member Author

KoBeWi commented Feb 2, 2023

Closing. This is wrong solution and the actual issue was identified to be different.

@KoBeWi KoBeWi closed this Feb 2, 2023
@KoBeWi KoBeWi added the archived label Feb 2, 2023
@KoBeWi KoBeWi deleted the potential_fix_or_maybe_not_who_knows branch February 2, 2023 13:22
@KoBeWi KoBeWi restored the potential_fix_or_maybe_not_who_knows branch February 6, 2023 09:22
@KoBeWi KoBeWi reopened this Feb 6, 2023
@KoBeWi
Copy link
Member Author

KoBeWi commented Feb 6, 2023

Reopening, as fixing the internal ids is high-priority matter and this works as a temporary fix.

@KoBeWi KoBeWi removed the archived label Feb 6, 2023
@KoBeWi KoBeWi force-pushed the potential_fix_or_maybe_not_who_knows branch 2 times, most recently from e373536 to 2a2d96f Compare February 6, 2023 09:25
scene/resources/resource_format_text.cpp Outdated Show resolved Hide resolved
@KoBeWi KoBeWi force-pushed the potential_fix_or_maybe_not_who_knows branch from 2a2d96f to 095c805 Compare February 7, 2023 13:13
@akien-mga akien-mga merged commit 07d46da into godotengine:master Feb 7, 2023
@akien-mga
Copy link
Member

Thanks!

@KoBeWi KoBeWi deleted the potential_fix_or_maybe_not_who_knows branch February 7, 2023 16:04
@ashelleyPurdue
Copy link

You mentioned that this was probably not a "correct" fix because it breaks something else. What is this other thing that it breaks, out of curiosity?

@KoBeWi
Copy link
Member Author

KoBeWi commented Feb 9, 2023

That was before I updated the PR. It used to set path for resources that ignore cache (i.e. they are supposed to be temporary). Now it only sets ID, which shouldn't break anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some resources will randomly reset their UID
4 participants