0

I'm using C# in Unity and I'm using the code here to free a C++ compiled dll (native plugin in Unity) that is loaded via code like this:

[DllImport ("ASimplePlugin")]
private static extern int PrintANumber();

The dll has a global variable that keeps some state. I'm using a counter there to test this. My assumption is that after calling FreeLibrary and then trying to run again, any state I had in my library would be gone and so it would start over. But that's not what is happening. Rather, each time I run it, it appears to continue where it left off and not reset.

I see no errors and the FreeLibrary call is returning true.

mentics
  • 6,852
  • 5
  • 39
  • 93
  • Are you using p/invoke to `LoadLibrary` and `FreeLibrary`? If you are, make sure you're calling `FreeLibrary` twice. Are you running this in VS? – t0mm13b Jun 03 '17 at 11:22
  • I call FreeLibrary multiple times and it returns true every time. I'm running it in Unity. – mentics Jun 03 '17 at 11:28
  • Then in this case, perhaps, Unity is holding on to the library as part of the overall process, when you exit the application, it should do the cleanup. – t0mm13b Jun 03 '17 at 11:39
  • 1
    Why do you call `FreeLibrary` manually if you load library implicitly? – user7860670 Jun 03 '17 at 11:43
  • 1
    I'm trying to force a reload of the dll, thus calling FreeLibrary and then I want to load it again. – mentics Jun 03 '17 at 12:35
  • I think @t0mm13b is right. Unity won't let go of it. So, I'll make it so the DLL handles resetting it's state instead of trying to reload the whole thing. – mentics Jun 03 '17 at 13:43

1 Answers1

0

from "Dreamora" in this unity forums post:

This problem is a consequence that Unity sadly still does not use seperate environments for the play mode and the editor so what you load in play mode is there in the editor

orion elenzil
  • 4,484
  • 3
  • 37
  • 49