Avoid import dock cleanup for non-loadable assets #82490
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.