Answer the question
In order to leave comments, you need to log in
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() { /*...*/ }
}
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();
}
}
/*...*/
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question