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

Closing a gdscript in the editor, choosing "Discard" and immediately re-opening it, shows old discarded content #50578

Open
andrea-calligaris opened this issue Jul 18, 2021 · 7 comments · May be fixed by #63246 or #78159

Comments

@andrea-calligaris
Copy link
Contributor

andrea-calligaris commented Jul 18, 2021

Godot version

3.3.2.stable.official

System information

Ubuntu

Issue description

Closing a gdscript in the editor and choosing "Discard" and then immediately re-opening it, actually loads its last state, while not actually saving the changes on file (at least).
This is very dangerous because it can lead to loose massive amounts of coding, especially if one does not know that the actual file has not been actually overwritten with the discarded content.

Steps to reproduce

  • Open the example project, or just create an empty project with at least two gdscripts.
  • Open both scripts in the editor.
  • Change one of the script, then close it, either by using the script list on the left or the context menu.
  • Immediately re-open the script.
  • See that the last state of the content of the script is given to the user, exactly as it was, even though you chose "Discard".

Update: having multiple scripts opened may not be needed to reproduce the bug.

Minimal reproduction project

DiscardScriptBug.zip

@andrea-calligaris andrea-calligaris changed the title Closing a gdscript in the editor and choosing "Discard" actually saves it Closing a gdscript in the editor and choosing "Discard" actually saves it, when more than one script opened in the editor Jul 18, 2021
@andrea-calligaris andrea-calligaris changed the title Closing a gdscript in the editor and choosing "Discard" actually saves it, when more than one script opened in the editor Closing a gdscript in the editor, choosing "Discard" and immediately re-opening it, shows old discarded content Jul 18, 2021
@andrea-calligaris
Copy link
Contributor Author

Bump, because it's rather serious IMHO.

@Hakunamawatta
Copy link
Contributor

I think this has to do with the editor changing the Script resource even before you save. So when you close the editor and then load the Script again, it uses the Script resource that's already loaded (with the changes). Is there a way to remove the changes made to a Script?

@Hakunamawatta
Copy link
Contributor

Hakunamawatta commented Jan 10, 2022

This is part of a larger issue: if you change a resource in the editor (scene editor or resource inspector), discard the changes, and then reload the resource that you changed (or the scene with the resource), then the changes will still be present. Something is holding onto these resources and preventing them from being freed. Strangely, this doesn't apply to Scenes, just the resources contained within.

@andrea-calligaris
Copy link
Contributor Author

andrea-calligaris commented Jan 10, 2022

@Hakunamawatta Changing e.g. a Theme resource never prompts for a discard when you switch to another resource. So we may accept that this is how it works in Godot, with resources. Which is rather bad but may be addressed in another issue.
However, closing a script prompts that dialog where you choose "Discard", so this is a bug regardless.
You also mention scenes, and in fact scenes has the same behaviour with the difference that choosing "Discard" actually works.

@Hakunamawatta
Copy link
Contributor

Hakunamawatta commented Jan 10, 2022

Choosing "discard" for scenes does not work entirely: as I mentioned, the changes made to Resources within those scenes remain after changes to a scene are discarded, even if the Resource is built-in. I think this issue is related to the issue of Scripts because Scripts are also Resources.

@Hakunamawatta
Copy link
Contributor

This is part of a larger issue: if you change a resource in the editor (scene editor or resource inspector), discard the changes, and then reload the resource that you changed (or the scene with the resource), then the changes will still be present. Something is holding onto these resources and preventing them from being freed. Strangely, this doesn't apply to Scenes, just the resources contained within.

Never mind. It seems like it's an unrelated issue that's not present in 4.0 whereas the Script issue is still in 4.0.

@honix
Copy link
Contributor

honix commented Jan 14, 2023

Interestingly closing with Ctrl+W works fine for me! Specifically closing via context menu have issue.

@kinami-imai kinami-imai linked a pull request Jun 12, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants