OnPreRender called before LateUpdate finishes

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)

Ok, I updated to Unity 5.6.1 and no more deadlock so it probably was indeed a bug.

Now it seems that dynamic batching breaks the rendering of my generated geometry in game view (scene view renders fine…) for some reason…
E: Turns out my instanced material had “enable instancing” disabled for some reason, thus allowing dynamic batching which broke the draw calls for some reason.

Actually I just got the deadlock again on 5.6.1.
Seems like it happens… Sometimes.

Someone? Unity staff? Anyone?
Is that occasional behaviour normal?

Bump?
I just might file a bug report.