Skip to content

Commit

Permalink
Fix GodotObject marshalling
Browse files Browse the repository at this point in the history
Godot Objects are encoded as `Object **`.
  • Loading branch information
raulsntos committed Sep 1, 2024
1 parent ddbd6bd commit b00d8f8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Godot.Bindings/NativeInterop/Marshalling.Ptr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,12 @@ public unsafe static T ConvertFromUnmanaged<[MustBeVariant] T>(void* value)

if (typeof(GodotObject).IsAssignableFrom(typeof(T)))
{
// If the pointer is null we can skip all the operations below.
if (value is null)
{
return default!;
}

if (typeof(RefCounted).IsAssignableFrom(typeof(T)))
{
// In virtual methods, if T is RefCounted we need to use `ref_get_object` to get
Expand All @@ -624,7 +630,14 @@ public unsafe static T ConvertFromUnmanaged<[MustBeVariant] T>(void* value)
{
value = refPtr;
}
else
{
// If the GodotObject is not RefCounted, the pointer is 'Object**'
// so we need to dereference it.
value = *(void**)value;
}
}

return (T)(object)GodotObjectMarshaller.GetOrCreateManagedInstance((nint)value)!;
}

Expand Down

0 comments on commit b00d8f8

Please sign in to comment.