Skip to content

Update unlock dll file - #36

Closed
tylearymf wants to merge 1 commit into
mcpiroman:masterfrom
tylearymf:feature
Closed

Update unlock dll file#36
tylearymf wants to merge 1 commit into
mcpiroman:masterfrom
tylearymf:feature

Conversation

@tylearymf

Copy link
Copy Markdown

No description provided.

@mcpiroman

Copy link
Copy Markdown
Owner

OK, so why should we try to FreeLibrary for 2 seconds on Windows? I have not met any problems with single try.

@tylearymf

Copy link
Copy Markdown
Author

2 seconds is to prevent Unity from getting stuck. This submission is to solve the problem that the dll file cannot be replaced after unloading, and Unity prompts that the file is occupied.

@tylearymf

Copy link
Copy Markdown
Author

Because when the reference count of the dll object in the system is greater than 0, the file handle will not be released. You can see this:freelibrary

The reference count is decremented each time the FreeLibrary or FreeLibraryAndExitThread function is called for the module. When a module's reference count reaches zero or the process terminates, the system unloads the module from the address space of the process. Before unloading a library module, the system enables the module to detach from the process by calling the module's DllMain function, if it has one, with the DLL_PROCESS_DETACH value. Doing so gives the library module an opportunity to clean up resources allocated on behalf of the current process. After the entry-point function returns, the library module is removed from the address space of the current process.

@tylearymf

Copy link
Copy Markdown
Author

What I want is to replace the dll file without closing Unity after the dll unload.

@mcpiroman

Copy link
Copy Markdown
Owner

What I want is to replace the dll file without closing Unity after the dll unload.

Yes, ofc, but me and others were able to do that without your change.

Because when the reference count of the dll object in the system is greater than 0, the file handle will not be released.

Yes, I know, but because any given dll is loaded once, it's ref count is not greater than 1. Unless it is loaded in some other way, either manually with 'LoadLibrary', or likely in some unexpected way by Unity.

I think we should first investigate why the upstream way does not work for you. Do you have some additional assemblies? Do you have additional threads, coroutines? Maybe can you confirm this problem exists with some basic hello world project?

@tylearymf

tylearymf commented Dec 29, 2021

Copy link
Copy Markdown
Author

Projects.zip

Please help me.
Open the Unity project (Projects/TestDll_Unity), then open the Scenes/SampleScene.unity scene, and then the Plugins/Test.Dll at this time is locked and cannot be deleted or replaced.

@mcpiroman

Copy link
Copy Markdown
Owner

Please open an issue describing your problem and the steps you follow, I'll close this PR for now.

@mcpiroman mcpiroman closed this Dec 29, 2021
@tylearymf

Copy link
Copy Markdown
Author

Ok, thank you. Maybe I tried it the wrong way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants