Hi there,
I’m hitting what might just be a corner case of the event functions API.
My code depends heavily on the execution order of the event functions since I need to retrieve native vertex and index buffers and bind them to fill them, both from native code.
I managed to do the former from a callback called from a native hook in LateUpdate and the latter from a GL issued plugin event from OnPreRender.
So it goes like this :
LateUpdate(); (C#)
UpdateNativeBuffers(); (C++ plugin) (mutex locked)
GetHandlers(); (C# again)
GetNativeVertexBufferPtr(); (Mesh API, syncs with the graphics thread)
OnPreRender(); (C#)
GL.IssuePluginEvent(); (syncs with the graphics thread)
FillNativeBuffers(); (C++ plugin) (mutex locked)
BindBuffers()
FillBuffers()
This works fine on OSX (OpenGL 4.1), iOS (Metal), Android (OpenGLES), Windows (DirectX11).
However, sometimes when targeting windows in OpenGL (4.5), I get a mutex lock because UpdateNativeBuffers owns the lock and before the callback to C# FillNativeBuffers() is called on the graphics thread, resulting in a lock, further locking the callback that would need to sync with the graphics thread as well because of the calls to Mesh.GetNativeVertexBufferPtr() and Mesh.GetNativeIndexBufferPtr().
Is this normal behaviour and should I redesign my code to work around that case or is there something fishy with the rendering events being called before LateUpdate completes?
(This was all tested with Unity 5.5.1, by the way)