Open AlmightyLaxz opened 1 year ago
I didn't consider that there may be non-readonly properties with a null SetMethod. https://github.com/godotengine/godot/pull/71128 should fix it.
[Context: This bug is so elusive and hard to catch, that I cannot reproduce it reliably enough to isolate a proper issue. Here's a way it happened to me if it helps anyone. Using Godot 4.3-stable and a self-compiled build of 4.3-stable with PR #79731 baked in. Both of them worked the same. This makes it C#/Mono exclusive.]
The one thing that triggered this bug is this asset from the Asset Library. It's not the asset itself that causes this. This bug happened unexpectedly (while on a game jam), even if under the same conditions it worked before.
The conditions were:
[Export]
attribute attached to the derived class. Could derive from any Godot object, or anything below done by the programmer. (same circumstances as described on the issue, but on a larger scale)[Export]
property were both on auto-set property and fields. This one happened on the asset above.dotnet clean
could fix anything.The only solution was:
project.godot
file and the .tscn
files to remove some broken script references.virtual
properties to abstract
.dotnet clean
from the terminal.dotnet build
from the terminal.It might've been a game-breaker for many. Some steps might look unnecessary but they were in this particular case. The game was so tainted by several days of having this time bomb lurking that I did lose some code, and thankfully I did have some working backups to fall back into.
I did find a comment on the ScriptPropertyDefValGenerator.cs file that kind of makes me think of something.
I am not a professional C# programmer, nor expert in the field, but I did find a pattern:
I write this after quite a while of figuring out the details of this bug... but I cannot reproduce them 100% reliably, mainly because the aforementioned evasive nature of it. But my gut feeling is that it's not resolving this specific combination of abstraction correctly, and that, worst case, we should get a warning this pattern is not recommended and can cause later harm.
Godot version
v4.0.beta.mono.custom_build [56522f7f8] (with double)
System information
Arch Linux, Vulkan
Issue description
C# projects with a parent class including a virtual property that is then overridden & initialized in a child class appear to cause ScriptPropertiesGenerator & ScriptSerializationGenerator to fail to generate source.
The problem appears to be caused by #70483, the Source Generators run fine if built immediately before this PR was committed. I'm not sure how to debug the Source Generators for a more useful error/stack trace than below, sorry.
Parent Class
Child Class
If the initialized property override below is commented then the Source Generators work fine.
Warnings/Errors produced
Warnings produced when a child class overrides the initialized property from its parent:
Any
[Export]
properties then throw build errors as ScriptPropertiesGenerator failed:Steps to reproduce
Build the solution in the minimal reproduction project.
Minimal reproduction project
csharpbug_03c26d6.zip