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

DotNET: Deprecated signal causes build failure #101930

Closed
RedMser opened this issue Jan 22, 2025 · 6 comments · Fixed by #101970
Closed

DotNET: Deprecated signal causes build failure #101930

RedMser opened this issue Jan 22, 2025 · 6 comments · Fixed by #101970

Comments

@RedMser
Copy link
Contributor

RedMser commented Jan 22, 2025

Tested versions

  • Reproducible in latest master (f1c0b5b)

System information

Windows 10 - DotNET SDK v8.0.300

Issue description

See the build failure in https://github.com/godotengine/godot/actions/runs/12914187787/job/36013250581?pr=90049

My PR #90049 deprecates a signal on SceneTree which seems to cause a warning (which is treated as error).

B:\Godot\modules\mono\glue\GodotSharp\GodotSharp\Generated\GodotObjects\SceneTree.cs(856,11): warning CS0618: 'SceneTree.NodeC
onfigurationWarningChangedEventHandler' is obsolete: 'This signal is no longer available. Call 'update_configuration_info' on  
a 'Node' or 'Resource' to notify the editor of configuration info changes.' [B:\Godot\modules\mono\glue\GodotSharp\GodotSharp\
GodotSharp.csproj]

Silencing this warning should be the way to fix this I assume? Generated code snippet for reference:

    /// <summary>
    /// Represents the method that handles the <see cref="Godot.SceneTree.NodeConfigurationWarningChanged"/> event of a <see cref="Godot.SceneTree"/> class.
    /// </summary>
    [Obsolete("This signal is no longer available. Call 'update_configuration_info' on a 'Node' or 'Resource' to notify the editor of configuration info changes.")]
    public delegate void NodeConfigurationWarningChangedEventHandler(Node node);

    private static void NodeConfigurationWarningChangedTrampoline(object delegateObj, NativeVariantPtrArgs args, out godot_variant ret)
    {
        Callable.ThrowIfArgCountMismatch(args, 1);
        ((NodeConfigurationWarningChangedEventHandler)delegateObj)(VariantUtils.ConvertTo<Node>(args[0]));
        // ^^^^ This usage of the EventHandler type emits the warning!
        ret = default;
    }

    /// <summary>
    /// <para>Emitted when the <c>node</c>'s <see cref="Godot.Node.UpdateConfigurationWarnings()"/> is called. Only emitted in the editor.</para>
    /// </summary>
    [Obsolete("This signal is no longer available. Call 'update_configuration_info' on a 'Node' or 'Resource' to notify the editor of configuration info changes.")]
    public unsafe event NodeConfigurationWarningChangedEventHandler NodeConfigurationWarningChanged
    {
        add => Connect(SignalName.NodeConfigurationWarningChanged, Callable.CreateWithUnsafeTrampoline(value, &NodeConfigurationWarningChangedTrampoline));
        remove => Disconnect(SignalName.NodeConfigurationWarningChanged, Callable.CreateWithUnsafeTrampoline(value, &NodeConfigurationWarningChangedTrampoline));
    }

    protected void EmitSignalNodeConfigurationWarningChanged(Node node)
    {
        EmitSignal(SignalName.NodeConfigurationWarningChanged, node);
    }

Steps to reproduce

Minimal reproduction project (MRP)

N/A

@AThousandShips
Copy link
Member

AThousandShips commented Jan 22, 2025

Is the configuration to treat warnings as errors something users have control over?

This signal shouldn't be used in generated code if it is deprecated though, so that would be an issue

@RedMser
Copy link
Contributor Author

RedMser commented Jan 22, 2025

Is the configuration to treat warnings as errors something users have control over?

Yes!

parser.add_argument("--werror", action="store_true", default=False, help="Treat compiler warnings as errors.")

But I think in the CI we want to avoid warnings, so treating them as errors is correct.

@AThousandShips
Copy link
Member

So this is specific to CI, my bad, the code generation should probably be changed here, the question is if it should generate handlers etc. for a deprecated signal or not, and if it should I assume it should be adding warning supressions appropriately

Has there not been any other deprecated signals so far?

@RedMser
Copy link
Contributor Author

RedMser commented Jan 22, 2025

Has there not been any other deprecated signals so far?

There are EditorPlugin.project_settings_changed and Resource.setup_local_to_scene_requested but their generated code does not include the Trampoline function, so they don't use any deprecated things.
Probably different scenario because SceneTree is a singleton? I'm not a C# user so I'm just guessing :D

@AThousandShips
Copy link
Member

Then it looks like we're just missing the correct code in code generation, or it is handled safely for those signals and it just doesn't work for singletons for some reason

I'd suggest someone with C# knowledge should dig through the code generator and see

Or just generate the C# code and see what those signal handlers output, they might just be adding some magic that this case just doesn't because of some edge case

@raulsntos
Copy link
Member

The Trampoline function is generated when the signal has parameters, it's not really related to singletons. It just so happens that both EditorPlugin.project_settings_changed and Resource.setup_local_to_scene_requested are parameterless so they don't generate a Trampoline function1.

The Trampoline function is just a private implementation detail, it's generated to serve as a bridge between the C++ signal and the C# event. So you could say it's part of the code generated to implement the C# event that corresponds to a signal, if that signal is deprecated I think it makes sense to deprecate the Trampoline function as well, thus silencing the warning as suggested.

I went ahead and created a PR to do that: #101970

Footnotes

  1. The main purpose of the Trampoline function is to marshal the parameters from C++ objects into C# objects, so when the signal has no parameters, we don't need a Trampoline function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants