Mixedrealitytoolkit-unity: Scene with spatial understanding components crashes on IL2CPP (HoloLens)

Created on 3 Mar 2018  路  4Comments  路  Source: microsoft/MixedRealityToolkit-Unity

Overview

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.

Expected Behavior

The spatial mesh is rendered as is the case on .NET backend.

Actual Behavior

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."

Steps to reproduce

Unity Editor Version

2017.2.1

Mixed Reality Toolkit Release Version

2017.2.1

IL2CPP Spatial Mapping / Awareness

Most helpful comment

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

reillydonovan picture reillydonovan  路  3Comments

jimstack picture jimstack  路  3Comments

overedge picture overedge  路  3Comments

ritijain picture ritijain  路  3Comments

matatabi-ux picture matatabi-ux  路  3Comments