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](http://runningdimensions.com/blog/?p=5) 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`?
↧