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

Avoid import dock cleanup for non-loadable assets #82490

Conversation

nolandc
Copy link
Contributor

@nolandc nolandc commented Sep 28, 2023

This PR fixes a crash when changing the type of a file that is not loadable (e.g a CSV or file with the "keep file" option) and reimporting. Not all files in the editor return a valid file from Resource::load. If these are added to the need_cleanup list, it'll crash when attempting to load the resource during cleanup here.

Technically the cleanup code could also be updated to better handle non loadable resources, but I think it's simpler to just ensure need_cleanup doesn't contain these files.

One small problem that remains is that objects that reference the updated resource aren't auto saved, so if a user quits before saving, the next project load will still be referencing the old object. Out of scope for this PR though.

Project for reproducing the crash (on latest code, this bug is not in 4.1.1): reimport_crash.zip

Project for testing the fix: change_type_crash_test.zip. To test, set the sprite's texture to the image. Then update the image to "keep file" and reimport.

I think there are some potential improvements that could be made to handle files that don't actually load resources. There's currently no easy way to determine if a given path can be loaded into a resource without calling ResourceLoader::load and checking the result. ResourceLoader will always find a loader that "recognizes" the path, because ResourceFormatImporter technically recognizes all paths that can be imported. This logic is what allows the remapping of a file to it's imported file to work, but makes it more difficult to gracefully handle cases like CSV files or resources with "keep file" selected.

@akien-mga akien-mga merged commit 4e1fce3 into godotengine:master Oct 3, 2023
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

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.

4 participants