Hello I am trying to use FFTW dll for C# but i get the error: Code (CSharp): DllNotFoundException: libfftw3-3.dll The dll is in Assets > Plugins I used this repository: https://github.com/tszalay/FFTWSharp And followed this tutorial: I made this script trying to use it, but i get the error so it won't run: Code (CSharp): using System; using System.Runtime.InteropServices; using FFTWSharp; using UnityEngine; public class Test : MonoBehaviour { [SerializeField,Range(0,10)] private int _size; [SerializeField] private float[] data; [SerializeField] private float[] result; void Awake() { result = Ifft(data); } private static float[] Ifft(float[] data) { // Get the length of the array int n = data.Length; /* Allocate an unmanaged memory block for the input and output data. * (The input and output are of the same length in this case, * so we can use just one memory block.) */ IntPtr ptr = fftw.malloc(n * sizeof(double)); // Pass the managed input data to the unmanaged memory block Marshal.Copy(data, 0, ptr, n); // Plan the IFFT and execute it (n/2 because // complex numbers are stored as pairs of doubles) IntPtr plan = fftw.dft_1d(n / 2, ptr, ptr, fftw_direction.Backward, fftw_flags.Estimate); fftw.execute(plan); // Create an array to store the output values float[] ifft = new float[n]; // Pass the unmanaged output data to the managed array Marshal.Copy(ptr, ifft, 0, n); // Do some cleaning fftw.destroy_plan(plan); fftw.free(ptr); fftw.cleanup(); // Scale the output values for (int i = 0, nh = n / 2; i < n; i++) ifft[i] /= nh; // Return the IFFT output return ifft; } } What have i done wrong here?
I fixed the error, i had a 32 bit dll instead ot the 64 bit version. But since fixing that - now unity immediately crashes to desktop when i press play every time i run my script. I checked editor logs and it does not show any errors relating to my dll so i am a bit stuck on why that might be happening.
You should be able to import both 32-bit and 64-bit. Then mark each one in the inspector accordingly. Try changing your compile settings in player settings under configuration. That may help if it is a compatibility issue.
Thats not the issue at the moment. At the moment it just crashes to desktop when i press play. And i have no idea how to debug it.
How do you know it is not a comparability issue, have you done any testing to check/confirm this? You can use visual studio to debug. If you add a break-point when the script first starts getting called, then use visual studio to start the game. You can step down until something causes the crash.
I don't know - am new to using DLLs for unity that are not written in C#. But step through does nothing since unity crashes and VS will lock up if i use breakpoints. If i don't run the script that uses the DLL then unity runs fine.