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

If a resource is used as a key in a dictionary, it will be replaced by null when saving with ResourceSaver to a .tres file #57506

Closed
iamtoaster opened this issue Feb 1, 2022 · 12 comments · Fixed by #64812

Comments

@iamtoaster
Copy link
Contributor

Godot version

4.0.alpha1

System information

Windows 10

Issue description

If you have a custom resource with exported dictionary in it (let's call it ResB), and you use another custom resource as a key on that dictionary (ResA), then try to save it in .tres format, the resource that was used as a dictionary key will not be saved (replaced by a null) and following message will be printed to console:

  <Ошибка C++>   Method/function failed. Returning: "null"
  <Исходный код C++>scene/resources/resource_format_text.cpp:1509 @ _write_resource()
  <Трассировка стека>Main.gd:19 @ _ready()

I also found that this error only happens when you try to save to a .tres file. When I tried to save same resource to a binary .res everything worked as expected with resource being saved.

Also found that if you use that same resource (ResA) for more than as a dictionary key (say, in an exported variable) in the resource being saved (ResB) then the bug does not happen either.

Steps to reproduce

  1. Create two custom resources (ResA and ResB)
  2. Make sure ResB has an exported dictionary which uses instances of ResA as keys.
  3. Add at least 1 entry to the dictionary in ResB that uses an instance of ResA as a key.
  4. Try to save ResB to a .tres file using ResourceSaver.save("res://data.tres", ResBInstance)

Minimal reproduction project

ResourcesTest.zip
Simply run it. res://data.tres is the buggy output file, res://data.res is the same resource but in binary format (and also no bug)

@Bashar-Ahmed
Copy link

If this issue is available, then I would like to attempt this as a first contribution.

@Calinou
Copy link
Member

Calinou commented Feb 1, 2022

If this issue is available, then I would like to attempt this as a first contribution.

Feel free to look into fixing this 🙂

@Anaxan

This comment has been minimized.

@Zireael07

This comment has been minimized.

@Anaxan

This comment has been minimized.

@Calinou
Copy link
Member

Calinou commented Feb 1, 2022

@Anaxan Please don't derail other issues that are unrelated to this particular bug.

@Anaxan
Copy link

Anaxan commented Feb 1, 2022

I apoligize for any offense I've caused. That wasn't my intention.

@iamtoaster
Copy link
Contributor Author

I just found out this bug is also present on Godot 3.4.2 stable, can be reproduced with the same project (just remove the @ part of @exports and it will work)

@Bashar-Ahmed
Copy link

As far as I was able to gather the issue, the path_cache is NULL when the ResourceFormatSaverTextInstance::_write_resource is being called. Is this how it was meant to be?, because the path_cache is the path from which the resource is to be loaded. So what does it signify during saving a Resource. To correct this, we can set path_cache within the ResourceFormatSaverTextInstance::save function, but since the resource passed in the argument is const I was unable to figure out a way of doing it. Any potential solutions?

@Life4gal
Copy link
Contributor

Hi everyone, I have a PR that solved this problem.

see #64812 :)

@Life4gal
Copy link
Contributor

By the way, I came across this issue because of a bug of RSCC :)

@Prakkkmak
Copy link

I get the same issue on 4.2.2.stable, i used the my_data.tres as key of my dictionary and the references where null. I have changed keys to my_data.id and now it's working.

Another ismular issue : https://forum.godotengine.org/t/resources-being-set-to-null-in-game/45678

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

Successfully merging a pull request may close this issue.

8 participants