Search Unity

DLL Lock

Discussion in 'Editor & General Support' started by Toack, Feb 25, 2011.

  1. Toack

    Toack

    Joined:
    Dec 18, 2006
    Posts:
    109
    I'm developing this simple DLL and I need to close and reopen Unity every time I compile it. The DLL appears to be locked because it's loaded in the Unity Editor (when I hit play) and then it's never unloaded.

    I made the DLL print to a file the events on the DllMain() entry point getting this:

    OPEN UNITY:
    Nothing...

    HIT PLAY:
    DllMain(): DLL_PROCESS_ATTACH

    HIT STOP:
    Nothing...

    CLOSE UNITY
    DllMain(): DLL_PROCESS_DETACH

    It's clear to me that the DLL is attached when I hit play and never detached until I close Unity. This makes the developing task really hard, tedious and time consuming.

    Is there any way to force the dll to detach ? maybe I'm missing something obvious.

    Searching a little gave me the impression that there is some other people with the same problem but there is no answer/solution on the matter.

    If any, I would really appreciate it.

    Thanks.
     
  2. markharkness

    markharkness

    Unity Technologies

    Joined:
    Nov 2, 2010
    Posts:
    176
    I've not came across this before but you could right click and reimport the dll after you compile it.
     
  3. Toack

    Toack

    Joined:
    Dec 18, 2006
    Posts:
    109
    @RoflHarris you sound like this should not be the expected behavior on the DLL usage, but I still have the problem. Reimporting the DLL doesn't trigger a Process detach from it and since it's attached I can't update the file without closing Unity.

    Is there any Unity developer that could explain the process of attaching/detaching DLLs ? or at least tell me that this is the way to do it so I can give up trying to get a better workflow ?
     
  4. JFo

    JFo

    Joined:
    Dec 9, 2007
    Posts:
    217
    Hi!
    We have developed many unmanaged DLLs to use with Unity and the behavior has always been as you describe: the DLL is detached only when editor is closed.. Yes, it's pain to dev DLLs, so we have used standalone mono (same version as in Unity) to do the testing and
    only after that used it with Unity..

    You have to be careful when doing DLL inits in awake/start as these are called evefy time the you hit the play.. So use some "init done" checks inside DLL init.

    If Unity folks are able to do something about it in the future, it would greatly help the DLL usage with Unity..

    BR, Juha
     
  5. Toack

    Toack

    Joined:
    Dec 18, 2006
    Posts:
    109
    @JFo: Thank you! I'm doing exactly what you describe so I'm not that lost. It's still painful though.

    Cheers,
     
  6. Jashengmato

    Jashengmato

    Joined:
    Mar 23, 2013
    Posts:
    11
    Create a method to manually stop the threads and release all the resources.

    Invoke this method in OnApplicationQuit.

    This may work! :)
     
  7. chi

    chi

    Joined:
    Mar 1, 2010
    Posts:
    18
    Last edited: May 19, 2013