mcpiroman / UnityNativeTool

Allows to unload native plugins in Unity3d editor
MIT License
183 stars 18 forks source link

can't overwrite my .dll in Assets/plugins after the first "play" in unity editor #23

Closed GerardPerche closed 4 years ago

GerardPerche commented 4 years ago

I'm probably missing something. Here is the problem I have now: in the editor: play game, then stop. Then, with windows file explorer, I'm try to overwrite my __xxx.dll file in Assets/plugins => Windows tells my the file is used, and I can't overwrite to update it with a new version. Note: VS debugger was attached during play, and UnloadAll() has been called correctly. and SysUnloadDll returned true. Any idea?

mcpiroman commented 4 years ago

Not quite. Does it happen every time or it just stopped working at some point? Maybe it's something else that holds the reference, like VS debugger? (doubt it though). Or maybe you did something that made Unity itself loaded it, like including underscores in DllImport (which you shouldn't).

There was also an issue (#9) where someone claimed he had similar problem, but it turned out not to be quite specific to this tool, maybe even system-wide issue? He recently replied that "it now works" with recent Unity version.

You could also try to debug the reference count of your DLL using WinDBG or alike, I haven't done it myself though.

GerardPerche commented 4 years ago

Thanks for your reply ! Some more info:

mcpiroman commented 4 years ago

Has it worked even once and then stopped at some point? From your previous issue I assume it has. If so, have you done anything specific since then, like changing some properties / configuration in Unity?

GerardPerche commented 4 years ago

I'm not sure. But I think I used to work at the beginning of my tests.. I'm investigating...

GerardPerche commented 4 years ago

I think I found the solution. The issue was on my side, because of a delegate in relation with the dll (on C #/ unity side) that was not freed. Everything seems to be OK now, I think this issue can be closed. thanks again for your help !

mcpiroman commented 4 years ago

Interesting.. interesting enough that I would appreciate if you could share some detail on how that worked out. Afaik a dll shouldn't be locked by delegates whatsoever, only hard PE dependencies and LoadLibrary. This might be what #9 was about and might also help someone in the future. Anyway, glad it works now.