- Home /
Native Plugin Cleanup
I'm writing a native plugin for Windows in C++ and having some trouble with the development process. Because Unity doesn't release the plugin dll after running it once, it is necessary to close Unity before I can modify the dll. This is obviously not ideal, so as a work around I manually load and release the dll in a script at runtime. This works for simple plugins, but for plugins that hook into Unity's rendering system I've been finding that calling FreeLibrary
from OnApplicationQuit
isn't safe because the OpenGL thread might continue running afterwards. For instance, if I call glDebugMessageCallback(), and I unload the library, the callback function is no longer valid. I can't unregister this callback in OnApplicationQuit because I need to be on the rendering thread to do so.
Here is the stack trace:
00007fff914403f0() <- Missing function nvoglv64.dll!0000000072b40617() nvoglv64.dll!000000007290feec() Unity.exe!GfxDeviceGLES::BeginProfileEvent(class ProfilerInformation *) Unity.exe!GfxDeviceWorker::RunCommand(class ThreadedStreamBuffer &)
So my problem basically boils down to: where should I free my dll if not in OnApplicationQuit
?
Also, see here for the approach to load and unload dlls at runtime.
Your answer
Follow this Question
Related Questions
What is the correct location for a native (C++) plugin's DLL dependencies 1 Answer
Where does Unity5 look for native plugin dependencies in the editor on Windows? 1 Answer
DllNotFound Exception on Editor but works on Standalone 0 Answers
Texture2D manipulation in c++ dll Plugin 0 Answers
Overall quality became worse after changing to Windows from Mac 1 Answer