I wanted to have a simple scene that visualizes the spatial mapping mesh as the HoloLens scans. The example scene only worked in the editor, so I've rebuilt the scene with the same prefabs and deployed it on a HoloLens which worked on the .NET backend. However, when on IL2CPP it crashes when calling the native function GeneratePlayspace_InitScan.
I looked into the native sources and the underlying DLL seems to use the cdecl calling convention. However, as far as i know the CLR on Windows x86 defaults to stdcall for P/Invoke, so I'm not entirely sure why it works at all if that is the case.
The spatial mesh is rendered as is the case on .NET backend.
The app crashes with the error message "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."
2017.2.1
2017.2.1
Might want to open this on the main Mixed Reality Toolkit
The bug is in the bindings though; I guess there's no error on the native side.
It'd be possible to change the calling convention to __stdcall there, but I'm not sure whether that's desired or if it breaks other platforms. So I think the better solution is to annotate the DllImports with CallingConvention.Cdecl.
Ahh, thanks for clearing that up.
I'm going to try to do that and report back if it works.
Edit: Alright, changing all DllImport("SpatialUnderstanding") to include CallingConvention.Cdecl fixes the problem. It seems Microsoft's CLR deals with that automatically and Unity's Mono doesn't.
I'll file a pull request soon and I'd appreciate if someone with access to an MR headset can test this to make sure my changes don't break other platforms. Then again, there's only one calling convention on x64 afaik.
Most helpful comment
I'm going to try to do that and report back if it works.
Edit: Alright, changing all
DllImport("SpatialUnderstanding")to includeCallingConvention.Cdeclfixes the problem. It seems Microsoft's CLR deals with that automatically and Unity's Mono doesn't.I'll file a pull request soon and I'd appreciate if someone with access to an MR headset can test this to make sure my changes don't break other platforms. Then again, there's only one calling convention on x64 afaik.