x


How do I unload a dll plugin?

Hello,

I'm having trouble with a dll. It crashes(freeze) on the second test. This is probably because the dll cannot be loaded twice (it communicates with drivers), and Unity does not unload when I stop testing.

I found this command:
FreeLibrary(GetModuleHandle("TestDll"));

but it gives this error: Assets/TestScript.cs(76,17): error CS0103: The name `FreeLibrary' does not exist in the current context

Does anyone have an idea how I can use FreeLibrary, because I can't find the dependency for it.

I'm using Unity 3.1 with Windows 7.

Thanks :)

Siewart

more ▼

asked Dec 10 '10 at 06:28 PM

Siewart gravatar image

Siewart
1 2 2 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I do not believe that such a function exists in mono as it is not cross-platform and I can find no such function with the API. According to MSDN, FreeLibrary is a function defined in Winbase.h. I'm pretty sure you cannot or should not be trying to use it in this context.

I feel that you are correct in that your dll usage is likely failing to release certain needed resources, but I am not certain if it is because the dll is not unloaded although it may well be the case. I know that I find it frustrating to be working on a dll and to have to restart Unity in order to remove the write protection placed on the dll if I ever run my game from the editor. This write protection indicates that Unity still has the dll loaded and depending on what that entails, it may be driving your problem but, in my experience, every time a dll I was using in Unity crashed, it was my own fault rather than some resources being tied up by having the dll loaded.

Did you consider that perhaps your dll is either doing something erroneous or being used erroneously? Are you using threading and when you stop execution, do you ensure that all threads are terminated first? Do you allocate any resources that you don't free up? Without more details on the dll and its usage, I can only guess at what might be wrong in the event that it is not because the dll is still loaded.

more ▼

answered Dec 10 '10 at 07:47 PM

skovacs1 gravatar image

skovacs1
10k 11 25 91

Hey thanks for your quick reply. I am using the CLNUIDevice.dll (http://www.nuigroup.com/forums/viewthread/11249/) with a Kinect. But I cant work on this project, because there is a new Kinect driver available, and I can't have both drivers installed at the same time...

I have checked with Process Explorer if the dll was loaded on testing the app, and checked if it was unloaded after that. I also use the Stop and Destroy functions to stop the connections with the Kinect.

-Siewart

Dec 12 '10 at 01:17 PM Siewart

I do not feel it is a problem of not unloading the dll as I (and others) have dlls in use and can start and stop the game preview in the editor any number of times without crashing. If crashing were the behaviour when a dll was not unloaded, then everyone would experience it. I think that the dll allocates some resources with CreateNUIMotor and CreateNUICamera and when you stop the game preview, your DestroyNUIMotor and DestroyNUICamera are not called, meaning that when you start the preview again, it tries to allocate the resources again. Try calling them in MonoBehaviour.OnApplicationQuit.

Dec 13 '10 at 03:54 PM skovacs1

Sorry for my very late reply, a better Kinect framework has been released (openNI.org), but I haven't tried it yet, because the Kinect still is at the university.

I already used this:

void OnApplicationQuit(){
    print("Stopping Kinect Connections");
    CLNUIDevice.SetMotorLED(mtr, 4);
    CLNUIDevice.SetMotorPosition(mtr, 0);
    CLNUIDevice.DestroyMotor(mtr);
    CLNUIDevice.StopCamera(cam);     
    CLNUIDevice.DestroyCamera(cam);
}

But that doesn't work. (It is called, though) But it still crashes when I run it for the second time.

Not sure if I still need an answer though.

Thanks for your time

Jan 02 '11 at 02:41 PM Siewart
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x231
x34
x20
x1

asked: Dec 10 '10 at 06:28 PM

Seen: 1651 times

Last Updated: Dec 10 '10 at 06:28 PM