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

ResourceLoader.CACHE_MODE_IGNORE does not ignore the resource cache #59669

Open
Hakunamawatta opened this issue Mar 29, 2022 · 4 comments
Open

Comments

@Hakunamawatta
Copy link

Godot version

4.0 (3b4e94c)

System information

Linux Mint 20.2

Issue description

When using ResourceLoader to load resources, CACHE_MODE_IGNORE should ignore the cache. At least for scripts, it seems to use the cache regardless. If the script is loaded with CACHE_MODE_IGNORE before there is anything in the cache, it adds the resource to the cache.

Steps to reproduce

  1. Create a new project
  2. Create two scripts
  3. Have one script load the other twice (one with the cache and one without the cache)
  4. Change the source code of the script loaded from the cache
  5. Print the source code of the script not loaded from the cache
  6. The source code is the same for both

Minimal reproduction project

Cache.zip

@Calinou Calinou added this to the 4.0 milestone Mar 29, 2022
@Calinou Calinou changed the title CACHE_MODE_IGNORE does not ignore the resource cache ResourceLoader.CACHE_MODE_IGNORE does not ignore the resource cache Mar 29, 2022
@Calinou
Copy link
Member

Calinou commented Mar 30, 2022

@Hakunamawatta Can you reproduce this in 3.4.4?

@Hakunamawatta
Copy link
Author

Hakunamawatta commented Mar 30, 2022

@Hakunamawatta Can you reproduce this in 3.4.4?

Partially. If you try to ignore the cache before something is loaded in the cache, then ignoring the cache will save it to the cache.

var same = ResourceLoader.load("res://other_script.gd", "", true)
var script = ResourceLoader.load("res://other_script.gd")
script.source_code = "#ASDFGHJKL"
print(same.source_code)

Whereas this doesn't change the source code of "same" because the cache isn't being used when loading:

var script = ResourceLoader.load("res://other_script.gd")
var same = ResourceLoader.load("res://other_script.gd", "", true)
script.source_code = "#ASDFGHJKL"
print(same.source_code)

But if you load from the cache again after ignoring the cache, then the source code of "same" will change (because it's being saved to the cache).

var script = ResourceLoader.load("res://other_script.gd")
var same = ResourceLoader.load("res://other_script.gd", "", true)
script = ResourceLoader.load("res://other_script.gd")
script.source_code = "#ASDFGHJKL"
print(same.source_code)

@YuriSizov YuriSizov modified the milestones: 4.0, 4.1 Feb 27, 2023
@YuriSizov YuriSizov modified the milestones: 4.1, 4.2 Jun 22, 2023
@YuriSizov YuriSizov modified the milestones: 4.2, 4.3 Nov 14, 2023
RandomShaper added a commit to RandomShaper/godot that referenced this issue Feb 26, 2024
- Unify documentation, hoping to clear misconcepctions about about propagation of the cache mode across dependant loads.
- Clarify in docs that `CACHE_MODE_REPLACE` now also works on the main resource (from godotengine#87008).
- Add two recursive modes, counterparts of `CACHE_MODE_REPLACE` and `CACHE_MODE_IGNORE`, since it seems some need them (see godotengine#59669, godotengine#82830).
- Let resources, even loaded with one of the ignore-cache modes, get a path, which is useful for tools.
@KoBeWi
Copy link
Member

KoBeWi commented Aug 3, 2024

There is new CACHE_MODE_IGNORE_DEEP now. Does it resolve the problem?

@Hakunamawatta
Copy link
Author

Hakunamawatta commented Aug 3, 2024

There is new CACHE_MODE_IGNORE_DEEP now. Does it resolve the problem?

No. Tested it with 4.3 RC 2

func _ready():
	var script = ResourceLoader.load("res://some_script.gd")
	var same = ResourceLoader.load("res://some_script.gd", "", ResourceLoader.CACHE_MODE_IGNORE_DEEP)
	script.source_code = '#This should not be in "same"'
	print("Same: ", same.source_code)

Output:

Same: #This should not be in "same"

@KoBeWi KoBeWi modified the milestones: 4.3, 4.x Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants