- Home /
PtrToStructure with array fields on iOS (ie AOT only mode)
Has anyone had any luck with getting PtrToStructure working with 'array' fields in a struct? I keep getting "Attempting to JIT compile method" error when attempting it.
For example:
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct TestByteArrayStruct {
public UIntPtr Length;
[MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst=1024)]
public byte[] Data;
}
And then at runtime you attempt to do something like:
TestByteArrayStruct test = (TestByteArrayStruct) Marshal.PtrToStructure(ptr, typeof(TestByteArrayStruct))
Works fine in the editor, but at runtime on iOS you will get:
ExecutionEngineException: Attempting to JIT compile method '(wrapper unknown) TestByteArrayStruct:PtrToStructure (intptr,object)' while running with --aot-only.
Which from my understanding/googling means the AOT compiler hasn't generated the appropriate method signature for that type.
The problem SEEMS to be with the UnmanagedType.ByValArray...
If I change it to be something like this...
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct TestByteArrayStruct {
public UIntPtr Length;
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst=1024)]
public string Data;
}
It will work fine.
I have a pretty big data structure that I want to use with various arrays of structs, but if UnmanagedType.ByValArray wont work I don't know what to do :(
Comment