Page 1 of 1

Phidget RFID & Unity IL2CPP Builds

Posted: Wed Jun 22, 2022 10:02 am
by DiBi
Hey,

We are trying to get the Phidget RFID device to work with IL2CPP Builds. Mono works fine, but IL2CPP throws the following exception when running the build, right after calling

Code: Select all

private static RFID _rfid;

private static void OpenDevice()
{
	_rfid = new();
	...
}
NotSupportedException: IL2CPP does not support marshaling delegates that point to instance methods to native code. The method we're attempting to marshal is: Phidget22.Phidget::nativeAttachEvent
at Phidget22.Phidget22Imports.Phidget_setOnAttachHandler (System.IntPtr phid, Phidget22.Phidget22Imports+AttachEvent fptr, System.IntPtr ctx) [0x00000] in <00000000000000000000000000000000>:0
at Phidget22.Phidget.initializeBaseEvents () [0x00000] in <00000000000000000000000000000000>:0
at Phidget22.RFID.initializeEvents () [0x00000] in <00000000000000000000000000000000>:0
at Next.Experimental.PhidgetRFID.PhidgetRFID.OpenThread () [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x00000] in <00000000000000000000000000000000>:0
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
Seems we are not even getting to the point where other 3rd party developers recommend to use the following attribute on static callback methods:

Code: Select all

[MonoPInvokeCallback( typeof( Phidget22.Events.RFIDTagEventHandler ) )]
private static void OnTag( object sender, Phidget22.Events.RFIDTagEventArgs e )
{
	...
}
Any ideas how we can solve this?

Cheers,
Dirk

Re: Phidget RFID & Unity IL2CPP Builds

Posted: Wed Jun 22, 2022 4:10 pm
by Patrick
If IL2CPP can't marshal instance delegates, then it can't be used with Phidget22. The library manages events internally. What platform are you targeting? Can you not use Mono?

-Patrick

Re: Phidget RFID & Unity IL2CPP Builds

Posted: Thu Jun 23, 2022 2:14 am
by DiBi
Hi Patrick,

Thanks for the prompt reply.

We are currently mostly targeting Windows platforms. The reason this issue came up is because our applications are technically demanding and thus quite performance-heavy. IL2CPP gives us a nice performance boost and we plan to use some of the Burst compiler features in the near future, which depends on IL2CPP.

I guess the best way to approach this and benefit from all the performance enhancement IL2CPP/Burst provides, is to use a standalone application that handles all Phidget Input and use a simple protocol like OSC to send the data over to Unity.

Cheers,
Dirk