5
5
50Dreams2019-12-27 10:18:44
Windows
50Dreams, 2019-12-27 10:18:44

IL2CPP + DLL, is it possible to make them friends?

Hello, Happy New Year to all ;)
In general, the problem is this -> I wrote a native plugin for 64-bit architecture, but it only works in the editor or on the Mono backend, and on the IL2CPP backend, the game crashes. We remove the function imported from my DLL - everything works like clockwork.
Exporting functions from C++:

#define DllExport __declspec( dllexport )
extern "C" {
  /*...*/
  DllExport int __stdcall Init(const char* modelPath, const char* haarcascadePath) { /*...*/ }
  /*...*/
  DllExport  void __stdcall ProcessImage(Color32** rawdata, Vector3* coords, int w, int h) { /*...*/ }
  /*...*/
  DllExport  void __stdcall Release() { /*...*/ }
}

Importing these functions in C#:
public class WebcamProcessing : MonoBehaviour
{
    /*...*/
    [DllImport("myawesomedll", EntryPoint = "Init", CallingConvention = CallingConvention.StdCall)]
    private static extern int Init(string detectionModelPath, string haarcascadePath);

    [DllImport("myawesomedll", EntryPoint = "ProcessImage", CallingConvention = CallingConvention.StdCall)]
    private static extern void ProcessImage(ref Color32[] rawImage, [In, Out] Vector3[] data, int width, int height);

    [DllImport("myawesomedll", EntryPoint = "Release", CallingConvention = CallingConvention.StdCall)]
    private static extern void Release();

    void Awake()
    {
        /* Инициализация вебки и, не имеющего ничего общего с проблемой, кода */
        int result = Init(GetFilePath("Название файла"), GetFilePath("Название файла"));
        if (result < 0)
        {
            /* Здесь ловим ошибки, если нативная сторона не смогла загрузить файлы */
        }
        else { Debug.Log("Inited - It's Fine!"); StartCoroutine(Processing()); }
    }
    IEnumerator Processing()
    {
        /* Ожидаем конца фрейма для запуска цикла */
        while (!_stop)
        {
            /* Запускаем код ниже каждый второй фрейм */
            _webCamTexture.GetPixels32(_colors);
            ProcessImage(ref _colors, _landmarksData, W, H);
            _texture.SetPixels32(_colors);
            _texture.Apply();
        }
    }
    /*...*/
}

Gives an error: SetPixels32 called with invalid number of pixels in the array.
As if the ProcessImage function was ignored.
And yet, how to make IL2CPP and dynamic library friends? Thanks in advance for any help!
EDIT: The game is built under Windows, so the appropriate dynamic libraries (.dll) are used.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2019-12-27
@freeExec

No, your library is not IL-code. It needs to be compiled separately for the native platform AndroidNDK and XCode, respectively, for your systems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question