Search Unity

Callback back into C# with arguments crashes from Hololens DLL

Discussion in 'VR' started by blainebell, Jul 13, 2017.

  1. blainebell

    blainebell

    Joined:
    Jun 10, 2016
    Posts:
    28
    I have developed a plugin that uses callbacks to call back into C#. I am trying to get this plugin to work on Hololens, and the Hololens emulator crashes at the end of the call to these callbacks. It has also been reported that this behavior happens on the Hololens as well: http://answers.unity3d.com/questions/1303963/hololens-callbacks-with-native-library.html

    I am currently using Unity 5.6.2f1, but it also crashes in the new 2017.1.

    Does anyone know how to avoid this crash? Callbacks work when there are no arguments. If I convert these arguments to IntPtr (e.g., for strings), the string can still be read, but it still crashes.

    I submitted a bug with an isolated project, but I thought that this forum could have a larger audience.

    Any help would be much appreciated!

    Thanks,

    Blaine
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    The issue in that post you mentioned is the fact that the calling convention on native and managed doesn't match. C++ defaults to __cdecl, while C# defaults to __stdcall. The solution is to annotate the callback pointers with "__stdcall" on the native side.
     
  3. blainebell

    blainebell

    Joined:
    Jun 10, 2016
    Posts:
    28
    that works, thanks!