Skip to content

Commit 391cd04

Browse files
committed
[fix] fix raising NullReferenceException in generating MethodBridge for MonoPInvokeCallbackAttribute while constructor arguments is empty.
1 parent 01754c8 commit 391cd04

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Editor/MethodBridge/Generator.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@ private static CallingConvention GetCallingConvention(MethodDef method)
559559
{
560560
return CallingConvention.Winapi;
561561
}
562+
if (monoPInvokeCallbackAttr.ConstructorArguments.Count == 0)
563+
{
564+
Debug.LogError($"MonoPInvokeCallbackAttribute on method {method.FullName} has no constructor arguments. Using CallingConvention.Winapi as default.");
565+
return CallingConvention.Winapi;
566+
}
562567
object delegateTypeSig = monoPInvokeCallbackAttr.ConstructorArguments[0].Value;
563568

564569
TypeDef delegateTypeDef;
@@ -580,7 +585,7 @@ private static CallingConvention GetCallingConvention(MethodDef method)
580585
throw new NotSupportedException($"Unsupported delegate type: {delegateTypeSig}");
581586
}
582587
var attr = delegateTypeDef.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute");
583-
if (attr == null)
588+
if (attr == null || attr.ConstructorArguments.Count == 0)
584589
{
585590
return CallingConvention.Winapi;
586591
}

0 commit comments

Comments
 (0)