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

Extension classes cause exception when used from C# #270

Closed
goncalo opened this issue Apr 11, 2023 · 11 comments · Fixed by #481
Closed

Extension classes cause exception when used from C# #270

goncalo opened this issue Apr 11, 2023 · 11 comments · Fixed by #481
Labels
bug Something that isn't working as intended external Involving an external party severity:major Significant impact on functionality or usability topic:runtime Concerning runtime behavior (or its source code)

Comments

@goncalo
Copy link

goncalo commented Apr 11, 2023

Calling methods on the physics server causes errors.

Example C# script:

public override void _Ready()
{
    var body = PhysicsServer3D.BodyCreate();
}

Error:

E 0:00:01:0088   ScriptManagerBridge.cs:263 @ System.Type Godot.Bridge.ScriptManagerBridge.<TypeGetProxyClass>g__GetTypeByGodotClassAttr|12_0(System.Reflection.Assembly , System.String ): System.NullReferenceException: Object reference not set to an instance of an object.
  <C# Error>     System.NullReferenceException
  <C# Source>    /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs:263 @ System.Type Godot.Bridge.ScriptManagerBridge.<TypeGetProxyClass>g__GetTypeByGodotClassAttr|12_0(System.Reflection.Assembly , System.String )
  <Stack Trace>  ScriptManagerBridge.cs:263 @ System.Type Godot.Bridge.ScriptManagerBridge.<TypeGetProxyClass>g__GetTypeByGodotClassAttr|12_0(System.Reflection.Assembly , System.String )
                 ScriptManagerBridge.cs:257 @ System.Type Godot.Bridge.ScriptManagerBridge.TypeGetProxyClass(System.String )
                 ScriptManagerBridge.cs:101 @ IntPtr Godot.Bridge.ScriptManagerBridge.CreateManagedForGodotObjectBinding(Godot.NativeInterop.godot_string_name* , IntPtr )
@goncalo goncalo changed the title Not able to use from C#. Not able to use from C# Apr 11, 2023
@mihe
Copy link
Contributor

mihe commented Apr 11, 2023

Thank you for reporting this!

I'll admit I haven't been testing C# as much as I should have, since I figured things would just work as long as you don't need to interact with any new node types exposed from the extension.

This error seems to be a general problem with objects derived from other GDEXTENSION_CLASS objects, which includes not only PhysicsServer3D but also PhysicsDirectBodyState3D and PhysicsDirectSpaceState3D.

So simply doing this seems to make the C# scripting emit a bunch of errors as well:

public override void _IntegrateForces(PhysicsDirectBodyState3D state)
{
}

I'll look into this right away.

@mihe mihe changed the title Not able to use from C# Derived objects trigger exception when used from C# Apr 11, 2023
@mihe
Copy link
Contributor

mihe commented Apr 12, 2023

It looks like this is an issue within Godot's C# integration, and not something that I can fix from the extension side of things. The relevant issue seems to be godotengine/godot#74801. I made a PR that seems to fix the problem: godotengine/godot#75955.

@mihe mihe added bug Something that isn't working as intended topic:runtime Concerning runtime behavior (or its source code) external Involving an external party labels Apr 12, 2023
@mihe mihe changed the title Derived objects trigger exception when used from C# Extension classes cause exception when used from C# May 18, 2023
@timshannon

This comment was marked as off-topic.

@mihe

This comment was marked as off-topic.

@mihe mihe added the severity:major Significant impact on functionality or usability label May 23, 2023
@timshannon

This comment was marked as resolved.

@mihe

This comment was marked as resolved.

@mihe
Copy link
Contributor

mihe commented Jul 6, 2023

The fix for this can be found in the newly released 0.4.0-rc1.

I would love it if everyone/anyone subscribed to this could give it a try and report back how it works for you.

@goncalo
Copy link
Author

goncalo commented Jul 7, 2023

Seems to be working properly now.
Thank you!

@timshannon
Copy link

Same for me. Working great now.

@mihe
Copy link
Contributor

mihe commented Jul 7, 2023

Great to hear. Thank you both.

I'll publish 0.4.0-stable first thing tomorrow.

@GeorgeS2019

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working as intended external Involving an external party severity:major Significant impact on functionality or usability topic:runtime Concerning runtime behavior (or its source code)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants