Skip to content

Commit c5257cd

Browse files
committed
fix SurfaceGetArrays
1 parent 6863665 commit c5257cd

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

internal/convert_types.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,18 @@ func VariantAs[T any](value Variant) T {
6363
case reflect.TypeFor[VariantPkg.Any]():
6464
return any(VariantPkg.New(value.Interface())).(T)
6565
case reflect.TypeFor[any]():
66-
return value.Interface().(T)
66+
// A NIL Godot Variant produces a Go nil interface, which cannot
67+
// be type-asserted to any (even though T == any); the assertion
68+
// would panic with "interface conversion: interface is nil, not
69+
// interface {}". Return the zero value of T (== nil for any)
70+
// instead, which is how callers like ArrayAs naturally treat
71+
// missing slots in e.g. Mesh.SurfaceGetArrays.
72+
iface := value.Interface()
73+
if iface == nil {
74+
var zero T
75+
return zero
76+
}
77+
return iface.(T)
6778
}
6879
result, err := ConvertToDesiredGoType(value, reflect.TypeFor[T]())
6980
if err != nil {

0 commit comments

Comments
 (0)