Fix Shader and ShaderInclude resource loading #80705
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.
Possibly also helps with some other issues like #79324. There have been several reports of deleted or renamed Shader resources somehow "haunting" a project, reappearing or otherwise causing some strange issues. These are possibly caused by the Shader resource loading logic which never fails even if you try to load a completely nonexistent Shader or ShaderInclude file, see #73975 for more details.
This PR adds error checking when loading these resources. In the linked issue MRP the crash happens because the scene file contains invalid references to a deleted
.gdshader
file:[ext_resource type="Shader" path="res://Shaders/planetShader.gdshader" id="1_3kkjf"]
and
shader = ExtResource("1_3kkjf")
Because currently loading this invalid resource actually succeeds it also makes the editor think that
Shaders
directory exists and when it tries to scan this invalid directory Godot crashes (becauseDirAccess:open()
return value is not checked).After this PR, trying to open the scene will correctly fail with an error message pointing to the missing file instead of silently creating invalid resources and then crashing Godot when trying to save the scene. If people have similar dangling resource references in their projects, they can no longer open and edit these scenes in the editor as the loading will fail. To fix this, they can either manually edit the .tscn file using an external text editor or create a temporary shader file where the missing one should be, then edit and adjust the scene inside the Godot editor. edit: Turns out there is also a scene dependency fixer functionality in the editor that can be used to fix this, live and learn.
This PR will also trigger some relatively untested code branches because previously Shader resource loading never failed. There are some conditions in the codebase that never failed previously, but after some testing they seem to work okay. Still, it's something to keep an eye out for.