godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.49k stars 21.07k forks source link

Shader editor randomly removes tabs from empty lines before saving #89331

Open Pshy0 opened 7 months ago

Pshy0 commented 7 months ago

Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.


Tested versions

System information

v4.3.dev4.official [df78c0636]

Issue description

I saved a .gdshader file with tabs on empty lines, and right before saving, tabs were removed. Then I saved another .gdshader file, and tabs were kept. This behavior should not be random, it should behave consistently. I would say the editor should not modify my file when I save it.

I noticed changing the file name, or making insignificant changes to the content, can change the behavior after godot restarts. Deleting .godot also sometime cause the behavior to change.

This may not be the only thing that the editor changes before saving. It does not save the last empty line either.

Steps to reproduce

Minimal reproduction project (MRP)

gdshader-trim.zip Note this includes the .godot folder because deleting it breaks it. Due to how random this was I would not be surprised if you need different shader files to observe the bug, so perhaps the MRP will not work.

AndersonMartins1 commented 7 months ago

It appears that you are experiencing an issue with the Godot editor's inconsistent behavior when saving .gdshader files. Here are some steps you can take to try to resolve or further investigate the issue:

Check Godot Editor Formatting Settings: Check if there are any settings in Godot editor related to formatting .gdshader files. Sometimes the editor may have automatic formatting options that are causing inconsistent behavior when saving files.

Testing on Other Versions of Godot: Try testing the issue on different versions of Godot to see if the inconsistent behavior persists. This can help determine if the issue is specific to a particular version or if it is a broader issue.

Check the Editor Saving Logic: If possible, review the Godot editor source code to understand how the .gdshader file saving logic is implemented. This can provide insights into why inconsistent behavior is occurring.

Testing on Different Operating Systems: If you are experiencing this issue on a specific operating system, try reproducing it on other operating systems to determine if the issue is platform related.

Report the Issue to the Godot Community: If you are unable to resolve the issue yourself, consider reporting the issue to the Godot community. This can be done through the Godot forum, GitHub, or other support platforms.

Try a Debugging Approach: If you have advanced debugging skills, you can try debugging the Godot editor to better understand what is causing the inconsistent behavior when saving .gdshader files.

Search for Related Issues: Search forums, GitHub issues, and other sources to see if other users have reported similar issues. This can provide additional clues about possible solutions or workarounds.

akien-mga commented 7 months ago

@AndersonMartins1 Is this an AI generated answer? If so, please refrain from posting this, it's very verbose and surface level at the same time, and not helpful for proper debugging of engine issues.

jsjtxietian commented 7 months ago

Did you by any change toggled the trim_trailing_whitespace_on_save setting? It will trim the tab and space for you on empty lines.

Related Code:

if (shader.is_null() && shader_inc.is_null()) {
    disk_changed->hide();
    return;
}

if (trim_trailing_whitespace_on_save) {
    trim_trailing_whitespace();
}

apply_shaders();

Ref<Shader> edited_shader = code_editor->get_edited_shader();
if (edited_shader.is_valid()) {
    ResourceSaver::save(edited_shader);
}
if (shader.is_valid() && shader != edited_shader) {
    ResourceSaver::save(shader);
}

Ref<ShaderInclude> edited_shader_inc = code_editor->get_edited_shader_include();
if (edited_shader_inc.is_valid()) {
    ResourceSaver::save(edited_shader_inc);
}
if (shader_inc.is_valid() && shader_inc != edited_shader_inc) {
    ResourceSaver::save(shader_inc);
}
code_editor->get_text_editor()->tag_saved_version();

disk_changed->hide();
Pshy0 commented 7 months ago

No. image

pancelor commented 7 months ago

I have also experienced this multiple times on 4.3.dev4, with the difference that I never even touched the shader editor tab in the bottom dock. I was doing unrelated work and an old shader suddenly showed changes when I ran git diff

Pshy0 commented 7 months ago

I noticed this too. It happens when saving, but sometime it re-saves shader files by itself.

Necronomicron commented 1 month ago

Has Trim Trailing Whitespace on Save option gone? Can't find it in 4.3. 🤔