Search Unity

Dll not found error

Discussion in 'Scripting' started by TheCelt, Jul 8, 2020.

  1. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    Hello

    I am trying to use FFTW dll for C# but i get the error:

    Code (CSharp):
    1. DllNotFoundException: libfftw3-3.dll
    The dll is in Assets > Plugins

    upload_2020-7-8_7-45-15.png

    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):
    1.  
    2. using System;
    3. using System.Runtime.InteropServices;
    4. using FFTWSharp;
    5. using UnityEngine;
    6.  
    7. public class Test : MonoBehaviour
    8.     {
    9.         [SerializeField,Range(0,10)] private int _size;
    10.  
    11.         [SerializeField] private float[] data;
    12.         [SerializeField] private float[] result;
    13.  
    14.         void Awake()
    15.         {
    16.             result = Ifft(data);
    17.         }
    18.  
    19.         private static float[] Ifft(float[] data)
    20.         {
    21.             // Get the length of the array
    22.             int n = data.Length;
    23.             /* Allocate an unmanaged memory block for the input and output data.
    24.              * (The input and output are of the same length in this case,
    25.              * so we can use just one memory block.) */
    26.             IntPtr ptr = fftw.malloc(n * sizeof(double));
    27.             // Pass the managed input data to the unmanaged memory block
    28.             Marshal.Copy(data, 0, ptr, n);
    29.             // Plan the IFFT and execute it (n/2 because
    30.             // complex numbers are stored as pairs of doubles)
    31.             IntPtr plan = fftw.dft_1d(n / 2, ptr, ptr, fftw_direction.Backward, fftw_flags.Estimate);
    32.             fftw.execute(plan);
    33.             // Create an array to store the output values
    34.             float[] ifft = new float[n];
    35.             // Pass the unmanaged output data to the managed array
    36.             Marshal.Copy(ptr, ifft, 0, n);
    37.             // Do some cleaning
    38.             fftw.destroy_plan(plan);
    39.             fftw.free(ptr);
    40.             fftw.cleanup();
    41.             // Scale the output values
    42.             for (int i = 0, nh = n / 2; i < n; i++) ifft[i] /= nh;
    43.             // Return the IFFT output
    44.             return ifft;
    45.         }
    46.     }
    What have i done wrong here?
     
  2. Cyber-Dog

    Cyber-Dog

    Joined:
    Sep 12, 2018
    Posts:
    352
    are you getting the error in Unity, or Visual Studio?
     
  3. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    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.
     
  4. Cyber-Dog

    Cyber-Dog

    Joined:
    Sep 12, 2018
    Posts:
    352
    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.
     
  5. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    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.
     
  6. Cyber-Dog

    Cyber-Dog

    Joined:
    Sep 12, 2018
    Posts:
    352
    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.
     
  7. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    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.
     
  8. Cyber-Dog

    Cyber-Dog

    Joined:
    Sep 12, 2018
    Posts:
    352
    Can you upload a slim version of your project. I can open it up and take a look for you.