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

Fix Script Editor saves C# files as embedded scripts. #88692

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

nongvantinh
Copy link
Contributor

@nongvantinh nongvantinh commented Feb 23, 2024

fixes: #88543
fixes: #88160

Because of the limitations of compiled programming languages like C#, when a newly created *.cs file hasn't been compiled, we don't have any information about its Path or Type in the assembly. This means we end up creating an invalid instance of this file whenever there's a request. Consequently, multiple instances of the script can exist. When a new instance takes over the path, it clears the path_cache of the previous instance, leading to undefined behavior.

@KoBeWi
Copy link
Member

KoBeWi commented Feb 23, 2024

If other instances of the script exist, taking over path will make them unlinked from the original resource. It might cause attached scripts to stop updating (relevant for tool scripts).

@nongvantinh
Copy link
Contributor Author

If other instances of the script exist, taking over path will make them unlinked from the original resource.

Just to clarify, the only scenario in which C# creates a different instance rather than using the previous one is when the C# script has not yet been compiled. Once it is compiled, there will be only one instance. I'm not sure about other scripting languages, though.

@KoBeWi
Copy link
Member

KoBeWi commented Feb 24, 2024

So I just realized

During the ResourceLoader::load process, the C# side creates a different instance and clears the path_cache of the old one, causing it to lose its path.

This points to a bug in C# loader, because CACHE_MODE_IGNORE is not supposed to do that.

@KoBeWi

This comment was marked as resolved.

@nongvantinh
Copy link
Contributor Author

Thanks for pointing this out, the new PR should correctly and safely fix the bug and any future bugs related to multiple instances of C# script.

@KoBeWi
Copy link
Member

KoBeWi commented Feb 25, 2024

While this works, it's not exactly how it should be implemented.
The code you added should take effect only when p_cache_mode is CACHE_MODE_IGNORE. Otherwise the new script should normally take over path.

@nongvantinh
Copy link
Contributor Author

Thanks. I was completely ignored the p_cache_mode parameter since it wasn't being used before. Now, I have modified it according to the latest document specifications. Please help me test it thoroughly.

fixes: godotengine#88543
fixes: godotengine#88160

Because of the limitations of compiled programming languages like C#, when a newly created *.cs file hasn't been compiled, we don't have any information about its `Path` or `Type` in the `assemply`. This means we end up creating an invalid instance of this file whenever there's a request. Consequently, multiple instances of the script can exist. When a new instance takes over the path, it clears the `path_cache` of the previous instance, leading to undefined behavior.
@akien-mga akien-mga merged commit 5059dd9 into godotengine:master Feb 26, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@nongvantinh nongvantinh deleted the fix-88543 branch February 26, 2024 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants